how to check record status?? [message #522199] |
Wed, 07 September 2011 04:53 |
|
new_oracle2011
Messages: 174 Registered: March 2011 Location: Qatar
|
Senior Member |
|
|
I am manually committing the form by writing commit statement in key - commit trigger for some reason.
Everything is working fine. I want to display a message if some necessary fields are not filled properly, like if a user filled half table and mistakenly he press the commit button. Here I want to show him a message that you can't saved the data because the table is not completely filled. Is this possible?
|
|
|
|
|
|
|
|
|
|
|
Re: how to check record status?? [message #522229 is a reply to message #522220] |
Wed, 07 September 2011 07:42 |
|
Baranor
Messages: 83 Registered: September 2011 Location: Netherlands
|
Member |
|
|
Well you could do a check that loops through the block, but it will require some kind of indicator that fields are required. It'll look something like this (mind you, this is for our own system, and I expect you use your imagination to fill in the blanks, and this piece of code is better placed in a library so you can acces it from every form, not just a single one).
declare
t_item varchar2(64);
t_mandatory boolean;
t_string varchar2(256);
t_display_message varchar2(1);
t_block varchar2(64);
begin
t_item := get_block_property(t_block,first_item);
--loop through all items in the current block of a form
while t_item is not null
loop
if get_item_property(t_block||'.'||t_item, item_type)
in ('TEXT ITEM','LIST')
then
t_manadatory := get_item_property(t_block||'.'||t_item, required);
else t_manadatory := 'FALSE';
end if;
if t_manadatory = 'TRUE'
then
if name_in(t_block||'.'||t_item) is null
then
t_display_message := 'J';
t_string := t_string ||' '||get_item_property(t_block||'.'||t_item , prompt_text);
end if;
end if;
t_item := get_item_property(t_block||'.'||t_item, nextitem);
end loop;
if t_display_message = 'J'
then
message('Please fill these:'||t_string );
message('Please fill these:'||t_string );
else
--all the mandatory fields have been filled, do something else.
end if;
end;
I wrote this particular code to enforce user-defined checks which were ignored if a call-form was used to merely look at data generated from a different form, which might not have been complete for the called-form but needed to be filled in. Since upon opening and quering the record status is valid, required fields are not triggered. Hitting exit_form at that point won't trigger the "required" messages. It's hooked beneath an OK-button and the commit-trigger to prevent going around it.
The other way is to manually define which records you need filled, and to check those, or to define them at database level and let the database send you back an error thus causing a trigger failure, stopping the execution of the code.
Hope you get something out of this. Good luck!
[Updated on: Wed, 07 September 2011 07:43] Report message to a moderator
|
|
|
Re: how to check record status?? [message #522231 is a reply to message #522229] |
Wed, 07 September 2011 08:04 |
cookiemonster
Messages: 13963 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
I can't remember off hand but I'm pretty sure the required property is checked before when-validate-record fires. And since you can't use key-commit for this as it can be bypassed (well you can but it means that sometimes you'll get the standard forms required message instead of what you coded) then I don't see this code being much help.
Set the required properties and let them do their job.
|
|
|
|
|
|
Re: how to check record status?? [message #522241 is a reply to message #522237] |
Wed, 07 September 2011 10:03 |
cookiemonster
Messages: 13963 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
According to the original post it's not all fields. If it was that'd work, as it isn't you'd have to store a list somewhere. At which point it probably becomes more work than just coding it the hard way.
|
|
|
|
|
Re: how to check record status?? [message #522306 is a reply to message #522294] |
Thu, 08 September 2011 03:48 |
cookiemonster
Messages: 13963 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
new_oracle2011 wrote on Thu, 08 September 2011 07:28
Cookiemonster: I might be wrong but to the best of my knowledge if we make the field as required in the property palette of that field or put a not null constraint in the table then the cursor will never move forward until the necessary field is filled by the user.
That's the default behaviour - it can be changed. Have a look at the defer required enforcement property at form level. Not null isn't checked until the record is submitted to the DB.
And I'll say again - key-commit can be bypassed. If the used makes changes and then exits the form (or presses enter query or exit query or clear block) the form will display a pop-up message asking if they want to save changes. If they click yes then the changes are saved without key-commit firing. So if you want to do validation you can't put it in key-commit.
|
|
|