Home » Developer & Programmer » Forms » form help
form help [message #635251] Wed, 25 March 2015 09:52 Go to next message
swetaranjan
Messages: 11
Registered: March 2015
Location: kolkata
Junior Member
Can any one suggest a logic for the below scenario
When user clicks on the checkboxes all the checkboxes should be checked except one . For the last unchecked one ,it will display a error when the user tries to check it.
I have taken count from the table and if the count is 1 it will show the message . also i have used this when checkbox change trigger. But when the user tried to uncheck the checked one same error comes . I dont want the error to come , when the user unchecks the checked one. Please suggest
Re: form help [message #635269 is a reply to message #635251] Wed, 25 March 2015 14:08 Go to previous messageGo to next message
Littlefoot
Messages: 21623
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
One option is to loop through all block records and count number of checked checkboxes. It can't be equal to total number of records.
Re: form help [message #635306 is a reply to message #635251] Thu, 26 March 2015 09:33 Go to previous messageGo to next message
CraigB
Messages: 386
Registered: August 2014
Location: Utah, USA
Senior Member
swetaranjan wrote on Wed, 25 March 2015 08:52
...I have taken count from the table and if the count is 1 it will show the message . also i have used this when checkbox change trigger. But when the user tried to uncheck the checked one same error comes . I dont want the error to come , when the user unchecks the checked one. Please suggest

This sounds like a logic error in your When-Checkbox-Changed trigger. Can you post your code? You likely just need to check the value of the Checkbox being changed before executing your code that reports the error.

Craig...
Re: form help [message #635332 is a reply to message #635306] Fri, 27 March 2015 01:57 Go to previous messageGo to next message
swetaranjan
Messages: 11
Registered: March 2015
Location: kolkata
Junior Member
Hi
Thanks for the response. I am using the below code in the trigger 'when checkbox changed'Its working bt when i am trying uncheck the checked one its showing the same mesg again.

BEGIN


select count(1) into v_count from Table_1 t1 where id = :block.item

AND t1.ship_to_status <> 'DELETED'
AND (t1.checkbox <> 'Y' or t1.checkbox <> is null);

IF v_count = 1 THEN


fnd_message.set_string('one checkbox should be there');
:block.checkbox := 'N';
fnd_message.error;
--RAISE FORM_TRIGGER_FAILURE;
else
Commit;
END;
Re: form help [message #635333 is a reply to message #635269] Fri, 27 March 2015 01:59 Go to previous messageGo to next message
swetaranjan
Messages: 11
Registered: March 2015
Location: kolkata
Junior Member
Hi

Thanks for the response .
Can you please give a sample code for refference. I havnt used loop before.

Re: form help [message #635353 is a reply to message #635332] Fri, 27 March 2015 08:43 Go to previous messageGo to next message
joy_division
Messages: 4949
Registered: February 2005
Location: East Coast USA
Senior Member
swetaranjan wrote on Fri, 27 March 2015 02:57

AND (t1.checkbox <> 'Y' or t1.checkbox <> is null);


That is invalid syntax so there is no way this could be your code.
Re: form help [message #635355 is a reply to message #635333] Fri, 27 March 2015 09:52 Go to previous messageGo to next message
CraigB
Messages: 386
Registered: August 2014
Location: Utah, USA
Senior Member
Committing each checkbox's value to the database is not a good idea; it creates too much network traffic and can make your form slow. Things like; is a checkbox checked, how many checkboxes are checked, etc., are all calculations that can occur in your form without a trip to the database. Also, try to avoid looping through a data block to determine a condition. This too will cause your form to appear slow. A better approach would be to use a calculated field in your data block and summarize the CHECKBOX item. This gives you a quick way of checking to see if any checkboxes are checked without having to loop through your block or have to make a trip to the database. In order to use a calculated field, you have to set the block property Query All Records = YES and then add a non-table item to your block. You can call this item anything you want, but I recommend something that suggests its purpose; for example: SUM_CHECKBOXES. Once you have the SUM_CHECKBOXES item added to your block, set the following properties:
1. Data Type = Number
2. Calculation Mode = Summary
3. Summary Function = Sum
4. Summarized Block = <Your Block Name here>
5. Summarized Item = <Name of your Checkbox Item here>
6. Number of Items Displayed = 1 (only if you are going to show this item on your canvas).
- - I recommend you display the item during testing just so you can see how the value changes as you check and uncheck checkboxes.
7. Database Item = No

Quote:
When user clicks on the checkboxes all the checkboxes should be checked except one . For the last unchecked one ,it will display a error when the user tries to check it.

Based on your requirement, you will need to add two additional Non-Table non-displayed items to your data block. The first is the REC_NUM and the second is a second Calculated Item that summarizes the number of records (REC_NUM) in your block so you can perform a comparison against the number of records in your When-Checkbox-Checked (WCC) trigger. First, add the REC_NUM non-table item to your block with these properties:
1. Data Type = Number
2. Database Item = No
3. Visible = No (Show it during development just so you can see how it gets changed)

Now add your second Calculated Item called SUM_RECS with these properties:
1. Data Type = Number
2. Calculation Mode = Summary
3. Summary Function = Sum
4. Summarized Block = <Your Block Name here>
5. Summarized Item = REC_NUM
6. Number of Items Displayed = 1 (Assuming your item is in a multi-record block, you don't want more than one showing)
7. Database Item = No
8. Visible = No (Show it during development just so you can see how it changes).

Now add the following triggers:
1. When-Create-Record
:YOUR_BLOCK.rec_num := 1;

2. Post-Query
IF (:YOUR_BLOCK.REC_NUM IS NULL) THEN 
  :YOUR_BLOCK.REC_NUM := 1;
END IF;

3. Finally alter your When-Checkbox-Checked trigger
IF ( Checkbox_Checked('YOUR_BLOCK.YOUR_CHECKBOX_ITEM') ) THEN
   IF ( :YOUR_BLOCK.SUM_CHECKBOXES = :YOUR_BLOCK.SUM_RECS ) THEN 
      :YOUR_BLOCK.YOUR_CHECKBOX := 0;  -- This ensures the checkbox is unchecked after you display your message.
      Clear_Message();
      FND_Message.SET_STRING('You can't Check all items!');
      FND_Message.Error;
   END IF;
END IF;

This method requires you to change the value of your Checkbox from a CHAR and values Y/N to Number and value 1/0. I also recommend you set the Check Box Mapping of Other Values to "Not Allowed" and your Value when Checked = 1 and Value when Unchecked = 0.

Now, when your user tries to click the last checkbox they will immediately see your message, 'one checkbox should be there'.

Hope this helps.
Craig...
Re: form help [message #635365 is a reply to message #635355] Fri, 27 March 2015 12:55 Go to previous messageGo to next message
Littlefoot
Messages: 21623
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Now THAT is a wonderful walkthrough!
Re: form help [message #635439 is a reply to message #635355] Mon, 30 March 2015 05:54 Go to previous message
swetaranjan
Messages: 11
Registered: March 2015
Location: kolkata
Junior Member
Thanks a lot. This was really helpful Smile
Previous Topic: Error control
Next Topic: execute a software
Goto Forum:
  


Current Time: Wed Nov 25 22:53:34 CST 2020