On a recent project I needed to set the value of some fields on a form, the values needed to be based on the the values set in a parent record, in fact the parents, parent record! This is to help users and speed up record creation time. I achieved this by using a client script with the “onLoad” type selected, as you can see below:
1 2 3 4 5 6 7 8 9 10 11 12 | function onLoad() { var 1 = g_form.getReference('parent.parent').field1; var 2 = g_form.getReference('parent.parent').field2; var 3 = g_form.getReference('parent.parent').field3; var 4 = g_form.getReference('parent.parent').field4; if(g_form.getValue('number') == ''){ g_form.setValue('field1', 1); g_form.setValue('field2', 2); g_form.setValue('field3', 3); g_form.setValue('field4', 4); } } |
I am setting variables based on the value of the fields in the parents parent record, I am using g_form to get the values, in particular g_form.getReference to retrieve the value of a reference field. I am also only setting the values if the number is blank, this ensures the record has not been inserted or saved first so the client script will only run once!
I have also renamed the variables / field names before publishing.
Thank you for reading.
#
I know this is not relevant to the topic mentioned here but I would like to know how I can subscribe for newsletter.
Thank you,
Nandan.
#
Hi Nadan,
We don’t currently have a news letter but may think of doing one in the future!
Thanks
Dan