Handover RECORD_ID to another form

Questions related to using nuBuilder Forte.

Handover RECORD_ID to another form

Unread postby oli » Tue Sep 21, 2021 12:35 am

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
oli
 
Posts: 85
Joined: Sat Mar 20, 2021 11:52 pm
nuBuilder Version: 4.5

Re: Handover RECORD_ID to another form

Unread postby nac » Tue Sep 21, 2021 7:33 am

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
nac
 
Posts: 72
Joined: Wed Dec 13, 2017 7:58 am
Location: Aberdeen, UK

Re: Handover RECORD_ID to another form

Unread postby kev1n » Tue Sep 21, 2021 3:53 pm

Another possibility is to use session storage (Example here)

And then use nuGetLookupId to populate the Lookup Object with that Primary Key.
kev1n
nuBuilder Team
 
Posts: 2059
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Handover RECORD_ID to another form

Unread postby oli » Thu Sep 23, 2021 11:44 pm

solved ! Thank you!
oli
 
Posts: 85
Joined: Sat Mar 20, 2021 11:52 pm
nuBuilder Version: 4.5

Re: Handover RECORD_ID to another form

Unread postby oli » Sun Sep 26, 2021 2:12 am

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:
Code: Select all
nuDebug("#CUST_ID#");


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:
Code: Select all
nuMessage(['Customer = ', fk]);
but I don't get any value for var fk.

Any ideas what's wrong here?
oli
 
Posts: 85
Joined: Sat Mar 20, 2021 11:52 pm
nuBuilder Version: 4.5

Re: Handover RECORD_ID to another form

Unread postby kev1n » Sun Sep 26, 2021 3:06 am

Use session storage. (see my post above)
kev1n
nuBuilder Team
 
Posts: 2059
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Handover RECORD_ID to another form

Unread postby oli » Sun Sep 26, 2021 7:13 am

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.
oli
 
Posts: 85
Joined: Sat Mar 20, 2021 11:52 pm
nuBuilder Version: 4.5

Re: Handover RECORD_ID to another form

Unread postby kev1n » Sun Sep 26, 2021 2:35 pm

This is wrong:
Code: Select all
nuCurrentProperties().cus


write:
Code: Select all
var cus = $("#pro_customer").val();
sessionStorage.setItem('PK_B',cus);
kev1n
nuBuilder Team
 
Posts: 2059
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5


Return to General

Who is online

Users browsing this forum: No registered users and 14 guests