Home » Developer & Programmer » Forms » Forms Button/Trigger (10g)
Forms Button/Trigger [message #653783] Mon, 18 July 2016 17:03 Go to next message
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 #653785 is a reply to message #653783] Mon, 18 July 2016 23:48 Go to previous messageGo to next message
1982Hashmi
Messages: 69
Registered: March 2011
Location: Islamabad
Member
You can use QUERY_HITS property to find whether any records are shown or not in detail block, and set visibility of that button accordingly.
Re: Forms Button/Trigger [message #653795 is a reply to message #653785] Tue, 19 July 2016 03:28 Go to previous messageGo to next message
cookiemonster
Messages: 13895
Registered: September 2008
Location: Rainy Manchester
Senior Member
When not just disable it from post-query in the detail block?
Re: Forms Button/Trigger [message #653826 is a reply to message #653795] Tue, 19 July 2016 11:20 Go to previous messageGo to next message
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 #653828 is a reply to message #653785] Tue, 19 July 2016 14:42 Go to previous messageGo to next message
jwang02
Messages: 26
Registered: May 2014
Location: Indiana
Junior Member
Could you please provide more detailed info about using this property?
Thank you very much for help.
Re: Forms Button/Trigger [message #653842 is a reply to message #653828] Wed, 20 July 2016 03:15 Go to previous messageGo to next message
cookiemonster
Messages: 13895
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 Go to previous messageGo to next message
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 Go to previous messageGo to next message
cookiemonster
Messages: 13895
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 #653904 is a reply to message #653882] Thu, 21 July 2016 16:57 Go to previous messageGo to next message
jwang02
Messages: 26
Registered: May 2014
Location: Indiana
Junior Member
Hi cookiemonster, thank you for your help!

Now the forms have been improved: after enabled the button on header POST-QUERY, it works!

But for the navigated records, the button is still not working.
I tried when-new-record-instance, got errors: Cannot displayed/enabled a button there.
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.
BTW, (:DETAIL_BLOCK.KEY_ITEM)seems always filled (:HEADER.KEY_ITEM) value since they joined together to retrieve detail data.

How to continue?
Re: Forms Button/Trigger [message #653907 is a reply to message #653904] Fri, 22 July 2016 00:05 Go to previous messageGo to next message
Littlefoot
Messages: 21616
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I'm returning to the first message in this discussion.

What problem are you trying to solve?

You said that the form won't allow users insert records if the detail block is empty, so you now have to create a button which will show up if the detail block IS empty and allow users enter data.

That sounds stupid. Why wouldn't you enjoy in Forms built-in, default functionality? First you forbid inserting, and now you have to reinvent the wheel and allow inserting.

What business requirement stands behind that behavior?
Re: Forms Button/Trigger [message #653926 is a reply to message #653904] Fri, 22 July 2016 03:33 Go to previous messageGo to next message
cookiemonster
Messages: 13895
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 #653944 is a reply to message #653926] Fri, 22 July 2016 17:50 Go to previous messageGo to next message
jwang02
Messages: 26
Registered: May 2014
Location: Indiana
Junior Member
1. The forms are old and modified by many people. After it loaded, the detail forms are only modifiable with key_items(joined with header table)existing. Otherwise, an error come out: The record does not exist. Now the business changed, and the users want to handle inserting. So a button was suggested to create to insert key_items to the detail table first. I didn't find anything blocking initial inserting. On the detail block, Insert/Update Allowed = Yes. What else to check?

2.I added GO_ITEM to WNRI trigger on header block, still got errors like
FRM-41051: You cannot create records here.
FRM-40105: Unable to resolve reference to item.

3. Is there other way to make the button able to go back on the navigated records, such as refreshing the whole master-detail data?

Thank you so much for your help, cookiemonster!

JW
Re: Forms Button/Trigger [message #653999 is a reply to message #653944] Mon, 25 July 2016 03:19 Go to previous messageGo to next message
cookiemonster
Messages: 13895
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 Go to previous messageGo to next message
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 #654032 is a reply to message #654029] Tue, 26 July 2016 00:08 Go to previous messageGo to next message
Littlefoot
Messages: 21616
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
It is not
GO_ITEM(:CONTROL.VENDOR_NAME);
but
GO_ITEM('CONTROL.VENDOR_NAME');
It is well described in Forms Help; why didn't you just look at it?

Once you fix it, are there any other errors?
Re: Forms Button/Trigger [message #654056 is a reply to message #654032] Tue, 26 July 2016 08:42 Go to previous messageGo to next message
jwang02
Messages: 26
Registered: May 2014
Location: Indiana
Junior Member
Yes, you're right. GO_ITEM('CONTROL.VENDOR_NAME'); is a good syntax on the Help.

However, on the trigger, without the two dots before the block name, you cannot compile the trigger/forms, and got error:

PL/SQL ERROR 201
identifier 'CONTROL.VENDOR_NAME' must be declared

???

Re: Forms Button/Trigger [message #654060 is a reply to message #654056] Tue, 26 July 2016 09:39 Go to previous messageGo to next message
cookiemonster
Messages: 13895
Registered: September 2008
Location: Rainy Manchester
Senior Member
Not in a call to go_item it won't.
Again, show the full code.
Re: Forms Button/Trigger [message #654067 is a reply to message #654060] Tue, 26 July 2016 10:44 Go to previous messageGo to next message
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 Go to previous messageGo to next message
cookiemonster
Messages: 13895
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 #654426 is a reply to message #654111] Tue, 02 August 2016 11:14 Go to previous messageGo to next message
jwang02
Messages: 26
Registered: May 2014
Location: Indiana
Junior Member
cookiemonster, sorry, I was out of my office for a week. Just came to review the project.

1) I tried to put the following 2 lines on WHNE-NEW-FORM-INSTANCE trigger. The forms work but the button still there. If the 1st line commented, error FRM-41051 comes out.
--GO_ITEM('CONTROL.VENDOR_NAME');
SET_ITEM_PROPERTY('CONTROL.ADD_VENDOR', displayed, PROPERTY_FALSE);
2) If a user tries to insert on the empty detail form after the forms loaded(the header form has data there), an alert comes out (the record does not exist) to stop inserting. The alert is from the forms Alerts list.
Re: Forms Button/Trigger [message #654450 is a reply to message #654426] Wed, 03 August 2016 03:33 Go to previous messageGo to next message
cookiemonster
Messages: 13895
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.
Re: Forms Button/Trigger [message #654654 is a reply to message #654032] Mon, 08 August 2016 15:06 Go to previous message
jwang02
Messages: 26
Registered: May 2014
Location: Indiana
Junior Member
My project is done now. The users are happy with the current solution.
I don't have to spend more time on it.
Thank you so much for your help, cookiemonster & Littlefoot!

[Updated on: Mon, 08 August 2016 15:09]

Report message to a moderator

Previous Topic: sequences not work in form 6i
Next Topic: check box
Goto Forum:
  


Current Time: Fri Oct 30 06:34:37 CDT 2020