Redirecting to another form by filling the foreign key

Questions related to using nuBuilder Forte.

Redirecting to another form by filling the foreign key

Unread postby absalom » Sun Apr 04, 2021 6:21 pm

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?
absalom
 
Posts: 23
Joined: Sat Apr 03, 2021 11:20 pm
nuBuilder Version: 4.5

Re: Redirecting to another form by filling the foreign key

Unread postby kev1n » Sun Apr 04, 2021 7:06 pm

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#'
kev1n
nuBuilder Team
 
Posts: 1624
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Redirecting to another form by filling the foreign key

Unread postby absalom » Sun Apr 04, 2021 9:57 pm

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?
absalom
 
Posts: 23
Joined: Sat Apr 03, 2021 11:20 pm
nuBuilder Version: 4.5

Re: Redirecting to another form by filling the foreign key

Unread postby kev1n » Sun Apr 04, 2021 10:04 pm

Try using the event onmousedown instead of onclick
kev1n
nuBuilder Team
 
Posts: 1624
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Redirecting to another form by filling the foreign key

Unread postby absalom » Sun Apr 04, 2021 10:11 pm

I tried onchange and onkeydown; finally I got it working with onfocus.
absalom
 
Posts: 23
Joined: Sat Apr 03, 2021 11:20 pm
nuBuilder Version: 4.5


Return to General

Who is online

Users browsing this forum: absalom, GlenMcCabe and 25 guests