- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2016 03:35 PM
Hi,
I would like to Auto Populate a String Field from a Reference Field.
So I have a Client Script on Load which populates the users Group. I would Like to use this Group Field (which is a Reference) to populate a String Field.
Here is my current scrip which does not work:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var svc= g_form.getValue("u_From");
if (svc == "UK Service Management") {
g_form.setValue("u_To_Desk", "UK");
}
}
The part of the Form that needs to be updated is the To Desk Field
So on the Form Loading it already populated the "Sent By" and "From"
Based on the "From" which is a reference it needs to Auto populate some writing in the "To Desk" string field.
Any ideas what I am doing wrong or how I can achieve this?
Thanks,
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2016 04:05 PM
Hi Riaz,
Two things:
- The field names will be all lower case (e.g.): u_from
- The value you get for the reference field 'u_from' will be the sys_id of the selected option ("UK Service Management"), not the displayed label
So, try this instead:
var svc = g_form.getValue('u_from');
if(svc == (sys_id of your desired option)){
g_form.setValue('u_to_desk', "UK");
}
If you want to easily see the value for your selected option of u_from, you can add a line for testing to your script after you've declared svc:
g_form.addInfoMessage(svc);
See if that helps.
-Brian
Edit: Also, if you are setting this up as an onChange script for the From field ('u_from' ), then you can just use the newValue parameter being passed to your script automatically instead of using g_form.getValue('u_from'):
var svc = newValue;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2016 04:05 PM
Hi Riaz,
Two things:
- The field names will be all lower case (e.g.): u_from
- The value you get for the reference field 'u_from' will be the sys_id of the selected option ("UK Service Management"), not the displayed label
So, try this instead:
var svc = g_form.getValue('u_from');
if(svc == (sys_id of your desired option)){
g_form.setValue('u_to_desk', "UK");
}
If you want to easily see the value for your selected option of u_from, you can add a line for testing to your script after you've declared svc:
g_form.addInfoMessage(svc);
See if that helps.
-Brian
Edit: Also, if you are setting this up as an onChange script for the From field ('u_from' ), then you can just use the newValue parameter being passed to your script automatically instead of using g_form.getValue('u_from'):
var svc = newValue;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2016 04:15 PM
Hi Brian,
Perfect! thank you very much I am going to Mark this as correct.
I changed to the sys id and works perfectly
Thank you very much
Riaz

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2016 04:18 PM
Great, glad it was that easy.
-Brian