Forms Button/Trigger [message #653783] |
Mon, 18 July 2016 17:03  |
 |
jwang02
Messages: 26 Registered: May 2014 Location: Indiana
|
Junior Member |
|
|
Hi Experts,
I need to create a button on master(one control section on the top)-detail(10 Tabs on the bottom) forms. When there is data showing up on the detail forms the button needs hidden, and If the detail forms null it needs showing up for users inserting detail data. The current forms don't allow inserting data when detail forms are null.
Where should I put the trigger to control the button? And how to write it?
Please help!
JW
|
|
|
|
|
Re: Forms Button/Trigger [message #653826 is a reply to message #653795] |
Tue, 19 July 2016 11:20   |
 |
jwang02
Messages: 26 Registered: May 2014 Location: Indiana
|
Junior Member |
|
|
Hi, Thank you very much for answering my question.
I created POST-QUERY Trigger under the detail block INDS_VENDOR_CONTRACTS as follows:
IF ((:INDS_VENDOR_CONTRACTS.YEAR is null) or (:INDS_VENDOR_CONTRACTS.VENDOR_ID is null)) THEN
SET_ITEM_PROPERTY('CONTROL.ADD_VENDOR', displayed, PROPERTY_TRUE); execute_query;
ELSE
SET_ITEM_PROPERTY('CONTROL.ADD_VENDOR', displayed, PROPERTY_FALSE); execute_query;
END IF;
(YEAR & VENDOR_ID are two columns linking the master and detail blocks, and only show up on master form for users to give values to retrieve data)
Unfortunately, the button only shows up when the forms initialized, and after data retrieved back, no matter the detail forms null or not, the button gone for ever. If no POST-QUERY trigger, the button stays there without change.
What's wrong now? Please help!
|
|
|
|
Re: Forms Button/Trigger [message #653842 is a reply to message #653828] |
Wed, 20 July 2016 03:15   |
cookiemonster
Messages: 13966 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Why on earth have you put execute_query in the post-query trigger?
Post-query fires for each record retrieved by a query on the block. If no records are retrieved then post-query doesn't fire, which is your problem. You use post-query to make it disappear but you need a different trigger to make it appear. Post-query on the header block would do.
|
|
|
Re: Forms Button/Trigger [message #653863 is a reply to message #653842] |
Wed, 20 July 2016 14:32   |
 |
jwang02
Messages: 26 Registered: May 2014 Location: Indiana
|
Junior Member |
|
|
Hi cookiemonster,
This time I created 2 one-line POST-QUERY triggers.
One on the header block to show the button:
SET_ITEM_PROPERTY('CONTROL.ADD_VENDOR', displayed, PROPERTY_TRUE);
One on the detail block to hide the button:
SET_ITEM_PROPERTY('CONTROL.ADD_VENDOR', displayed, PROPERTY_FALSE);
The button can come back and forth based on the detail forms with data or not.
However, 1. the button comes out greyed and cannot be highlighted
2. it cannot come out for a navigated record.
For example, after the forms loaded(both header and detail forms have no data), the button works.
After you searched YEAR 2016/VENDOR_ID 1 on the header form, and data shows up on the detail forms, the button disappears.
When you navigated 2016/2, the detail forms are null, the button shows up greyed.
If going back to 2016/1, the button gone. Navigated again to 2016/2, the button doesn't show up until a new combination(2016/3 & the detail forms have no data) navigated.
How to improve it now?
|
|
|
Re: Forms Button/Trigger [message #653882 is a reply to message #653863] |
Thu, 21 July 2016 03:13   |
cookiemonster
Messages: 13966 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Setting the displayed property to false automatically sets the enabled property to false as well, setting displayed to true doesn't set enabled to true. So set enabled to true.
Sounds like you need to move the code to when-new-record-instance on the header block. Check if a pk item on the detail block is null, if so enabled the button, else disable.
|
|
|
|
|
Re: Forms Button/Trigger [message #653926 is a reply to message #653904] |
Fri, 22 July 2016 03:33   |
cookiemonster
Messages: 13966 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
jwang02 wrote on Thu, 21 July 2016 22:57
I tried when-new-record-instance, got errors: Cannot displayed/enabled a button there.
That's because you can't disable the item the cursor is currently on, move the cursor to an item other than the button (using go_item) before disabling it.
jwang02 wrote on Thu, 21 July 2016 22:57
On the detail block POST-QUERY and other POST- triggers, enabling/disabling are no good.
It seems that POST-QUERY does not work with IF condition. I tried (:DETAIL.KEY_ITEM is not null), or select count(KEY_ITEM) into v_cnt from detail table where KEY_ITEM = (:HEADER.KEY_ITEM) and put v_cnt <> 0, neither worked out.
Again - post-query doesn't fire when no records are retrieved.
jwang02 wrote on Thu, 21 July 2016 22:57
BTW, (:DETAIL_BLOCK.KEY_ITEM)seems always filled (:HEADER.KEY_ITEM) value since they joined together to retrieve detail data.
When records have been retrieved that's obviously true. When they haven't it should be null, if it isn't you've done something wrong.
|
|
|
|
Re: Forms Button/Trigger [message #653999 is a reply to message #653944] |
Mon, 25 July 2016 03:19   |
cookiemonster
Messages: 13966 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
This:
Quote:
FRM-40105: Unable to resolve reference to item.
Is caused when you supply the name of an item that doesn't exist. Fix your typo.
I've no idea why you're getting the other error, it would help if you showed us the code.
|
|
|
Re: Forms Button/Trigger [message #654029 is a reply to message #653999] |
Mon, 25 July 2016 17:38   |
 |
jwang02
Messages: 26 Registered: May 2014 Location: Indiana
|
Junior Member |
|
|
POST-QUERY on detail block:
SET_ITEM_PROPERTY('CONTROL.ADD_VENDOR', displayed, PROPERTY_FALSE);
POST-QUERY on master block:
SET_ITEM_PROPERTY('CONTROL.ADD_VENDOR', displayed, PROPERTY_TRUE);
SET_ITEM_PROPERTY('CONTROL.ADD_VENDOR', enabled, PROPERTY_TRUE);
--Working above. Errows below, no matter IF condition and/or GO_ITEM(...) there or not
WHEN-NEW-RECORD-INSTANCE on master block:
Declare
v_count number;
Begin
GO_ITEM(:CONTROL.VENDOR_NAME);
select count(vendor_id) into v_count from INDS_VENDOR_CONTRACTS where year = (:control.YEAR) and vendor_id=(:control.VENDOR_ID);
--IF ((:INDS_VENDOR_CONTRACTS.YEAR is null) or (:INDS_VENDOR_CONTRACTS.VENDOR_ID is null)) THEN
IF v_count = 0 THEN
--GO_ITEM(:INDS_VENDOR_CONTRACTS.TERMS);
SET_ITEM_PROPERTY('CONTROL.ADD_VENDOR', displayed, PROPERTY_TRUE);
SET_ITEM_PROPERTY('CONTROL.ADD_VENDOR', enabled, PROPERTY_TRUE);
ELSE
SET_ITEM_PROPERTY('CONTROL.ADD_VENDOR', displayed, PROPERTY_FALSE);
END IF;
End;
|
|
|
|
|
|
Re: Forms Button/Trigger [message #654067 is a reply to message #654060] |
Tue, 26 July 2016 10:44   |
 |
jwang02
Messages: 26 Registered: May 2014 Location: Indiana
|
Junior Member |
|
|
The bug is now fixed with adding two single quotes around the item name. It was my mistake.
It should be GO_ITEM('CONTROL.VENDOR_NAME')as both of you pointed out, not GO_ITEM(CONTROL.VENDOR_NAME). My bad.
Thank you so much for your help!
I would still like to know:
1. From where and how to hide the button on an empty forms(both header and detail forms have no data)? I tried WHEN-NEW-FORM-INSTANCE, it did not work.
2. What can block users to insert detail data when the detail forms empty(Key Items YEAR/VENDOR_ID not existing in the table)?
(detail forms property Insert/Update Allowed=Y,
all columns on detail table can be null
and all triggers/program units checked, it seems nothing related to the inserting.)
[Updated on: Tue, 26 July 2016 14:40] Report message to a moderator
|
|
|
Re: Forms Button/Trigger [message #654111 is a reply to message #654067] |
Wed, 27 July 2016 02:41   |
cookiemonster
Messages: 13966 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
1) When you try something that doesn't work and want to know why you should always post the code and the error you got instead of making us ask every time.
2) Blocked how? Are you getting an error?
|
|
|
|
Re: Forms Button/Trigger [message #654450 is a reply to message #654426] |
Wed, 03 August 2016 03:33   |
cookiemonster
Messages: 13966 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
1) It helps if you post the error text as well as the error number, saves us having to look it up. It's you cannot create records here. Don't see how you can get that from just disabling a button. Suggest you run the form in debug mode to see what's going on, I can only assume some other code is interfering. Also use messages to check where the cursor actually is before and after you try to disable the button.
2) Well some code must be raising that error, I suggest you find it and see what it's doing.
|
|
|
|