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?
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Redirecting to another form by filling the foreign key
-
- Posts: 25
- Joined: Sat Apr 03, 2021 3:50 pm
-
- 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
The solution depends on how/where the form is opened (new tab, same breadcrumb, new breadcrumb) etc. See Related question)
Set a Hash Cookie in the button's onclick event:
In the 2nd form (in the form's Custom Code):
and in the 2nd form's Browse use that to filter like:
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.)A button for creating a new record in B with foreign key being automatically filled as A.id (and being invisible/uneditable).
Set a Hash Cookie in the button's onclick event:
Code: Select all
sessionStorage.setItem('PK_A',nuCurrentProperties().record_id);
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
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.A button for browsing records in B having foreign key being A.id
Code: Select all
nuSetProperty('PK_A', nuCurrentProperties().record_id, true)
Code: Select all
WHERE foreign_key = '#PK_A#'
-
- Posts: 25
- Joined: Sat Apr 03, 2021 3:50 pm
Re: Redirecting to another form by filling the foreign key
My button is a "Run" object; as long as I open the console before clicking the button for checking the value of
I have the relevant values, but if I add a
in the onclick event of the "Run" button, the fields get empty; maybe the Javascript is evaluated after the values have been reset?
Code: Select all
nuCurrentProperties()
Code: Select all
console.log(nuCurrentProperties())
-
- 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
Try using the event onmousedown instead of onclick
-
- Posts: 25
- Joined: Sat Apr 03, 2021 3:50 pm
Re: Redirecting to another form by filling the foreign key
I tried onchange and onkeydown; finally I got it working with onfocus.