Page 1 of 1

Start new form with prefilled data taken from other form

PostPosted: Thu Jan 03, 2019 2:42 am
by Janusz
I want to create a new record on new form with prefilled data taken from the current form.

Currently on one form lets say Form_1 I have a button with run command to open other form lets say Form_2 to enter a new record on it.
To have blank Form_2 I use - non existing value in the search field. And later I have to choose manually the reference with the "Lookup".

so the question - how to set-up on Form_2 in just in one field a value taken from one field from the Form_1.

So after Button press on Form_1 to have following sequence -> read value from Object_A on Form_1 -> Open Form_2 -> set value on Form_2 to Object_X equal to Object_A

Re: Start new form with prefilled data taken from other form

PostPosted: Thu Jan 03, 2019 3:05 pm
by ARWEN
Question: Is Form 2 openend in a popup window (iframe)? Then you can try something like this:

// add in form 2, custom javascript code:
Code: Select all
if (nuFormType() == 'edit') {
    // get value of object_A
    var objectA = $("#object_A", window.parent.document);
   // assign the value to object X
     $("#object_X').val(objectA).change();
}

Re: Start new form with prefilled data taken from other form

PostPosted: Mon Jan 07, 2019 6:03 am
by Janusz
Hi,
So far I was not able to link both forms.

Generally the problem I have is with the folowing line: var objectA = $("#object_A", window.parent.document);
(as objectA I use the value from the input field named ID which in my case is equivallent to the first column name of the table)

I was trying to make some modification to it, some other code like:
window.parent.document.getElementById('object_A')

but did not manage to make it working. Sometimes in the target field I have sothing like: [object Object]

do you have some more ideas how to proceed.

>>> more clarification to my case. I have full screen edit window on which there are some input fields and a button to open new window in a full screen mode. I want to read a value from one input field from the parent window and to place it in one field in opened window. The issue I have is - how to read a value from the parent window.

Re: Start new form with prefilled data taken from other form

PostPosted: Mon Jan 07, 2019 3:19 pm
by ARWEN
There was a val() missing in my code

Code: Select all
if (nuFormType() == 'edit') {
    // get value of object_A
    var objectA = $("#object_A", window.parent.document).val();
   // assign the value to object X
     $("#object_X').val(objectA).change();
}



and a button to open new window in a full screen mode.


What code is run in the button? What do you mean by "full screen mode" ? My code will only work if the 2nd window is opened in a popup window (iFrame)
Screenshots might be of help.

Re: Start new form with prefilled data taken from other form

PostPosted: Tue Jan 08, 2019 8:04 am
by Janusz
Hi, please find enclosed a file with the issue I am trying to resolve.
The main point is how to read value "2" on "Form A" with code placed in "Form B"

https://drive.google.com/file/d/1VcfnSF ... sp=sharing

so far I did not succeed with it.

Re: Start new form with prefilled data taken from other form

PostPosted: Tue Jan 08, 2019 3:06 pm
by kev1n
IMO there's no direct way to get a value from form A once form B is open. What I usually do is save the value before opening the 2nd form using Web Storage API.

To do so, change your existing button from Run type to Input type Button. Then add an onclick event:
Code: Select all
sessionStorage.setItem("Kontakty_id", $('#Kontakty_id').val()); nuForm('5c32367d36711a9','-1','', '');


(Replace 5c32367d36711a9 with the id of the Form B)

Then in Form 2, retrieve the value from session storage and assign it to cta_kont_ref
Code: Select all
if(nuFormType() == 'edit') {
    // set address if opened from an address
    var refA = sessionStorage.getItem("Kontakty_id");
    if(refA !== null) {
        $('#cta_kont_ref').val(refA).change();
    }
}
// Remove session storage
sessionStorage.removeItem("Kontakty_id");

Re: Start new form with prefilled data taken from other form

PostPosted: Sat Jan 12, 2019 6:37 pm
by Janusz
Working now - :-) - THANKS a lot.

but I was trying a lot with no success due to not proper assign of the form Id in my application,
for the following part of code:
Code: Select all
... nuForm('5c32367d36711a9','-1','', '');


and finally I used the method from
viewtopic.php?f=19&t=9787

what solved the issue.

Re: Start new form with prefilled data taken from other form

PostPosted: Sat Jan 19, 2019 8:11 am
by admin
.