Home » Developer & Programmer » Forms » Need help with Multi-Block procedure
Need help with Multi-Block procedure [message #307715] Wed, 19 March 2008 11:54 Go to next message
solisdeveloper
Messages: 48
Registered: March 2008
Location: Mexico
Member
Hi everyone:
I realy could use your help guys, so here's my situation:

I have 2 data blocks "blk_newusers" and "blk_oldusers" they both have the same items and data types and I'm trying to make a procedure to validate that there are no null items, but i want to make it in a way that i can use the same procedure for both blocks.

What i did was to create a procedure to wich I'm sending a string with the name of the block.

This is what I'm sending:
pr_validate_null_items (':blk_newusers');

And this is what my code looks like:

PROCEDURE pr_validate_null_items(p_block VARCHAR2)IS
BEGIN
  IF p_block || '.it_username' IS NULL THEN
    message ('The user name is null');
    RAISE form_trigger_failure;
  END IF;
END;


But when I run it, it simply does nothing, it seems like forms is actualy trying to check if the string ":blk_newusers.it_username" IS NULL, wich is obviously not

What am I doing wrong?
Can u help me?
Re: Need help with Multi-Block procedure [message #307753 is a reply to message #307715] Wed, 19 March 2008 15:56 Go to previous messageGo to next message
Littlefoot
Messages: 20901
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Why would you code something that Oracle does by itself? The simplest way is to create a table with NOT NULL columns; you won't be able to save any record which contains NULL values in corresponding form items.

Also, set the "Required" item property to YES.
Forms Online Help System
When an item has Required set to Yes, and item-level validation is in effect, by default Oracle Forms will not allow navigation out of the item until a valid value is entered.
For more information, read the "Required" property Usage Notes.
Re: Need help with Multi-Block procedure [message #307760 is a reply to message #307753] Wed, 19 March 2008 17:26 Go to previous messageGo to next message
solisdeveloper
Messages: 48
Registered: March 2008
Location: Mexico
Member
Hum...Ok I apreaciate the help LittleFoot, but nevermind the not null validation, that's not what worries me, the thing is that in my form I'll be constantly runing procedures in both data-blocks and instead of making two diferent procedures with the very same functionality, but with the only diference being the name of the data-block, I'd rather make 1 generic procedure that receives the name of the block and then do all due validations necesary.

So my question is how can I do the following IF statements like the ones below? This is how my code looks like but when I run my form it's not working, I'm obviously doing something wrong when i concatenate the block and field I guess, because Forms simply ignores them:

(p_block is a varchar2 variable containing the name of the block that i need to validate dinamically)

PR_VALIDATE_USER (p_block VARCHAR2) IS
BEGIN
  IF p_block || '.it_age' > 30 THEN
    p_block || '.it_category' := 2;
  END IF;

  IF p_block || '.it_haschilden' = 'YES' THEN
    set_item_property(p_block || '.it_numberofchildren',ENABLED, property_true);
next_item;
  END IF;
END;


In a few words, my questions is:
How can I concatenate a varchar2 variable containing the name of a block, to the name of an Item in order to evaluate the value that the item contains by using an IF statement?

Thanks i really need the help on this.
Re: Need help with Multi-Block procedure [message #307774 is a reply to message #307760] Wed, 19 March 2008 18:35 Go to previous messageGo to next message
djmartin
Messages: 10180
Registered: March 2005
Location: Canberra ACT Australia
Senior Member
Account Moderator
Pass the contents of the item, not the block name that refers to it.

David
Re: Need help with Multi-Block procedure [message #307775 is a reply to message #307774] Wed, 19 March 2008 18:38 Go to previous messageGo to next message
solisdeveloper
Messages: 48
Registered: March 2008
Location: Mexico
Member
But what changes is actually only the name of the block, the Items on both have the same name and same data type.

Any suggestions?
Re: Need help with Multi-Block procedure [message #307777 is a reply to message #307775] Wed, 19 March 2008 18:56 Go to previous messageGo to next message
djmartin
Messages: 10180
Registered: March 2005
Location: Canberra ACT Australia
Senior Member
Account Moderator
Try
procedure PR_VALIDATE_USER (
  p_age           in       number,
  p_cat           in out   number,
  p_haschildren   in       varchar2,
  p_block         in       varchar2) IS
BEGIN
  IF p_age > 30 THEN
    p_cat := 2;
  END IF;
  IF p_haschilden = 'YES' THEN
    set_item_property (p_block || '.it_numberofchildren',
                       ENABLED,
                       property_true);
  END IF;
END;

The only other alternative I can think of is using dynamic SQL and I think that that is overkill.

David
Re: Need help with Multi-Block procedure [message #307782 is a reply to message #307777] Wed, 19 March 2008 20:02 Go to previous messageGo to next message
solisdeveloper
Messages: 48
Registered: March 2008
Location: Mexico
Member
Thank you David, I'm going to try that.

although suggestions are still wellcome hehe
Re: Need help with Multi-Block procedure [message #307980 is a reply to message #307782] Thu, 20 March 2008 11:45 Go to previous message
solisdeveloper
Messages: 48
Registered: March 2008
Location: Mexico
Member
Hi everyone:

Well I finally solved it with a little help from a friend who reminded me of a Built-In that came out to be quiet useful.

My problem was that when I tried this: IF p_block || 'it_haschildren' = 'YES'... Forms was actually trying to compare the two Strings ":blk_newusers.it_haschildren" and "YES" instead of retreiving the value contained in :blk_newusers.it_haschildren and then compare it whith "YES"

This is how my code looks like and it works perfectly for any given Form in wich I may want to validate my user's data.

PR_VALIDATE_USER (p_block VARCHAR2) IS
BEGIN
  :GLOBAL.valueof := NAME_IN(':' || p_block || '.it_haschilden');
  IF :GLOBAL.valueof = 'YES' THEN
    set_item_property(':' || p_block || '.it_numberofchildren',ENABLED, property_true);
    next_item;
  END IF;
END;


So now I can use this procedure everytime I want to validate the item it_haschildren, no matter what form I'm working on or the name of the block that I'm using.

I thought about posting it in case somebody was trying the same. Thanks for all your help and advices.

Regards!
Previous Topic: urjent need pdf book for D2K
Next Topic: Internal Server Error
Goto Forum:
  


Current Time: Fri Dec 09 23:07:34 CST 2016

Total time taken to generate the page: 0.12306 seconds