Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Handover RECORD_ID to another form

Questions related to using nuBuilder Forte.
Post Reply
oli
Posts: 118
Joined: Sat Mar 20, 2021 3:22 pm
Has thanked: 4 times

Handover RECORD_ID to another form

Unread post 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
nac
Posts: 115
Joined: Tue Dec 12, 2017 11:28 pm
Location: Aberdeen, UK
Has thanked: 9 times
Been thanked: 12 times

Re: Handover RECORD_ID to another form

Unread post 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
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Handover RECORD_ID to another form

Unread post by kev1n »

Another possibility is to use session storage (Example here)

And then use nuGetLookupId to populate the Lookup Object with that Primary Key.
oli
Posts: 118
Joined: Sat Mar 20, 2021 3:22 pm
Has thanked: 4 times

Re: Handover RECORD_ID to another form

Unread post by oli »

solved ! Thank you!
oli
Posts: 118
Joined: Sat Mar 20, 2021 3:22 pm
Has thanked: 4 times

Re: Handover RECORD_ID to another form

Unread post 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:

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?
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Handover RECORD_ID to another form

Unread post by kev1n »

Use session storage. (see my post above)
oli
Posts: 118
Joined: Sat Mar 20, 2021 3:22 pm
Has thanked: 4 times

Re: Handover RECORD_ID to another form

Unread post 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.
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Handover RECORD_ID to another form

Unread post by kev1n »

This is wrong:

Code: Select all

nuCurrentProperties().cus
write:

Code: Select all

var cus = $("#pro_customer").val();
sessionStorage.setItem('PK_B',cus);
Post Reply