Page 1 of 1

Return Selected Lookup ID

Posted: Sat Sep 08, 2018 2:04 pm
by tonyd
I have a form with several lookup objects
FormLookupObject.JPG
each object has a 'SHOW' button that is meant to popup an edit form to show details about the selected lookup object. My difficulty lies in how to retrieve a field from the current database record using Ajax.

Is there an easy way to do this already available? I have looked through the functions in nucommon.js, nuform.js, and nuajax.js but don't see anything that stands out.

Re: Return Selected Lookup ID

Posted: Sat Sep 08, 2018 5:44 pm
by toms
Hi,

All you need is the form id (of your Edit Form) and then use this openRecordInPopup() function to pass the form id and the field id of your the lookup object.

Code: Select all

function openRecordInPopup(frm, fld) {
    var obj = nuSubformObject('');
    var idx = obj.fields.indexOf(fld);
    recId = obj.rows[0][idx];
    nuPopup(frm, recId);
}

E.g. (replace with your form id and field id)
openRecordInPopup('5a5f6af5d27e4c1', 'your_field_id');
The Form Id can be determined by opening the edit form and entering nuCurrentProperties().form_id in the Console (F12). The Form Id is then output.

Re: Return Selected Lookup ID

Posted: Sat Sep 08, 2018 9:10 pm
by tonyd
Thanks Toms, that worked perfectly.

Do you also have a simple way to get the form ID if you know the form name so I won't have to look up the IDs manually. I just foresee a bug showing up in my code if the form ID changes for some reason, like when deleting and recreating a form.

Thanks again!

Re: Return Selected Lookup ID

Posted: Sat Sep 08, 2018 10:50 pm
by toms
You would have to write a PHP procedure to lookup a form id from a form name.
It's not a big deal if you need know some PHP. Let me know if you need any help with it.

Re: Return Selected Lookup ID

Posted: Sun Sep 09, 2018 12:08 am
by admin
.