Welcome to the nuBuilder Forums!

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

Redirecting to another form by filling the foreign key

Questions related to using nuBuilder Forte.
Post Reply
absalom
Posts: 25
Joined: Sat Apr 03, 2021 3:50 pm

Redirecting to another form by filling the foreign key

Unread post by absalom »

Hi, being on an edit form for a given record (having "id" as its id on current table A), I would like to put two buttons for leaving the current form and redirecting to other forms related to table B:

A button for creating a new record in B with foreign key being automatically filled as A.id (and being invisible/uneditable).

A button for browsing records in B having foreign key being A.id

How can I achieve that?
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Redirecting to another form by filling the foreign key

Unread post by kev1n »

The solution depends on how/where the form is opened (new tab, same breadcrumb, new breadcrumb) etc. See Related question)
A button for creating a new record in B with foreign key being automatically filled as A.id (and being invisible/uneditable).
Using sessionStorage allows you to transfer a value from one form to another, regardless of where it is opened (New Breadcrumb, new tab, came Breadcrumb etc.)

Set a Hash Cookie in the button's onclick event:

Code: Select all

sessionStorage.setItem('PK_A',nuCurrentProperties().record_id); 
In the 2nd form (in the form's Custom Code):

Code: Select all

var  fk = sessionStorage.getItem('PK_A'); // Retrieve the PK of Table A
sessionStorage.removeItem('PK_A'); // Remove the item from session storage
$('#Object_FK_ID)').val(fk).change(); // Assign the fk value to the object with ID "Object_FK_ID" on the 2nd form
A button for browsing records in B having foreign key being A.id
Set a global Hash Cookie in the button's onclick event. It the form is going to be opened in the same Breadcrumb, the third parameter can be omitted.

Code: Select all

nuSetProperty('PK_A', nuCurrentProperties().record_id, true)
and in the 2nd form's Browse use that to filter like:

Code: Select all

WHERE foreign_key = '#PK_A#'
absalom
Posts: 25
Joined: Sat Apr 03, 2021 3:50 pm

Re: Redirecting to another form by filling the foreign key

Unread post by absalom »

My button is a "Run" object; as long as I open the console before clicking the button for checking the value of

Code: Select all

nuCurrentProperties()
I have the relevant values, but if I add a

Code: Select all

console.log(nuCurrentProperties())
in the onclick event of the "Run" button, the fields get empty; maybe the Javascript is evaluated after the values have been reset?
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Redirecting to another form by filling the foreign key

Unread post by kev1n »

Try using the event onmousedown instead of onclick
absalom
Posts: 25
Joined: Sat Apr 03, 2021 3:50 pm

Re: Redirecting to another form by filling the foreign key

Unread post by absalom »

I tried onchange and onkeydown; finally I got it working with onfocus.
Post Reply