- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 03:34 PM
Hello all,
I have a catalog item im working on where im trying to populate some information based on the user in the requested for field, things are working except the location field and the manager field, can anyone spot what is wrong with my client script?
Client script: onChange
Variable name: requested_for
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var empInfo = g_form.getReference('requested_for', userDetails);
function userDetails(empInfo){
g_form.setValue('employee_number', empInfo.user_name);
g_form.setValue('job_title', empInfo.title);
g_form.setValue('location', empInfo.location.name);
g_form.setValue('manager_name', empInfo.manager.name);
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 03:41 PM
You can't do dot walking using getreference.
So your script should be
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var empInfo = g_form.getReference('requested_for', userDetails);
function userDetails(empInfo){
g_form.setValue('employee_number', empInfo.user_name);
g_form.setValue('job_title', empInfo.title);
g_form.setValue('location', empInfo.location);
g_form.setValue('manager_name', empInfo.manager);
}
}
And you variables should be reference fields. So location should be a reference field to cmn_location and manager should be a reference field to sys_user.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 04:10 PM
Once you set manager and location as reference fields, you will be able to use the following code as Sanjiv mentioned above.
g_form.setValue('location', empInfo.location);
g_form.setValue('manager_name', empInfo.manager);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 06:06 PM
I have set them to referene fields and the values are still not populating.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 04:10 PM
Hi othomas,
Client Script doesnt allow you to do dot walk. Mainly because the client side is already loaded with data and it only will have the sys_id for the reference field, so dot walking a sys_id doesnt make sense to system. For server side scripting when you dot walk, being a server side script it actually goes inside the reference field to obtain the data. Hope that makes sense.
Now, for the solution, the best thing to do would be to use the Manager and the Location field in the form as a reference field so that you can set the value in those fields with your client script like you are doing but with just a minor variation - "g_form.setValue('location',empInfo.location);" etc.
Otherwise, you can call a script include as mentioned in the previous answers only if your fields are of string type and you want to populate the Location and Manager with string data.
Cheers,
Sam