Page 1 of 1
Handover RECORD_ID to another form
Posted: Mon Sep 20, 2021 5:05 pm
by oli
Hello,
is there a way to open a new record from a another edit form (of another object) but to handover the current record ID and use it to prefill a lookup object in the new record?
e.g.:
I want to open a new TASK in the edit form of an existing PROJECT.
The RECORD_ID of the current project should be used to prefill the lookup object in the new TASK.
BR,
Oli
Re: Handover RECORD_ID to another form
Posted: Tue Sep 21, 2021 12:03 am
by nac
Hi oli,
You can use nuSetProperty to set a hash cookie value that will persist for the duration of the session. This means it can be set on one form and then picked put later on another form. You need to use the optional third parameter, set to true e.g.
Code: Select all
nuSetProperty("MY_ID",nuCurrentProperties().record_id,true);
This will create the hash cookie #MY_ID# using the ID of the record. This can then be used later in the WHERE clause of the SQL code for the lookup browse form.
I hope this helps.
Neil
Re: Handover RECORD_ID to another form
Posted: Tue Sep 21, 2021 8:23 am
by kev1n
Another possibility is to use
session storage (Example here)
And then use
nuGetLookupId to populate the Lookup Object with that Primary Key.
Re: Handover RECORD_ID to another form
Posted: Thu Sep 23, 2021 4:14 pm
by oli
solved ! Thank you!
Re: Handover RECORD_ID to another form
Posted: Sat Sep 25, 2021 6:42 pm
by oli
I still have an issue with handing over an id and it would be great if somebody can help me.
I set a hash cookie in a run object that is opening a new EDIT Form where I want to set the Customer ID in a lookup object with following Custom Code on the RUN object:
Code: Select all
var cus = $("#pro_customer").val();
nuSetProperty("CUST_ID", cus, true);
On the target form (where the customer ID should be used to set the value in the lookup object for Customers) I can see the correct ID with PHP:
On the target form I used following custom code to set the ID in the lookup object (ite_customer):
Code: Select all
var fk = $("#CUST_ID").val();
nuGetLookupId(fk, 'ite_customer'); // Write ID to Lookup for Customer
But it seems the hash cookie can't be used in the JAVA Script.
It looks like there is no value.
I tried it with:
but I don't get any value for var fk.
Any ideas what's wrong here?
Re: Handover RECORD_ID to another form
Posted: Sat Sep 25, 2021 7:36 pm
by kev1n
Use session storage. (see my post above)
Re: Handover RECORD_ID to another form
Posted: Sat Sep 25, 2021 11:43 pm
by oli
I tried it with following code but it didn't work too.
1st Form to get the customer id (Custom code on run object):
Code: Select all
var cus = $("#pro_customer").val();
sessionStorage.setItem('PK_B',nuCurrentProperties().cus);
target form to set value in lookup object "ite_customer":
Code: Select all
var fk = sessionStorage.getItem('PK_B'); // Retrieve the PK of Table A
sessionStorage.removeItem('PK_B'); // Remove the item from session storage
nuGetLookupId(fk, 'ite_customer'); // Write ID to Lookup for Customer
var fk is still empty.
Re: Handover RECORD_ID to another form
Posted: Sun Sep 26, 2021 7:05 am
by kev1n
This is wrong:
write:
Code: Select all
var cus = $("#pro_customer").val();
sessionStorage.setItem('PK_B',cus);