Returning Record from the Script Include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 12:39 PM - edited 04-01-2025 12:40 PM
Dear Members,
I have designed the Script Include which is returning the User data to the Catalog Client Script. After selecting the Employee Id in the Catalog Item it is showing the Employee Name as [object Object] instead of User name.
Please suggest.
Catalog Client Script: -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 12:55 PM - edited 04-01-2025 01:16 PM
Hi @NehaSNOW ,
You don't need to write GlideAjax, instead use the Auto-populate feature and get the desire column value of selected user record.
If you have 3 different field on form, open the field definition page and select the Auto-Populate tab and select the User Field name in Dependent Question, first two field will be same for all 3 field only, change the dot walk path for each one.
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 01:30 PM
Hi @NehaSNOW
In my example that does something similar, my client script call-back function has:
function EmployeeDetailsLookup(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var result = JSON.parse(answer);
g_form.setValue('requested_for',result.name);
g_form.setValue('cost_center',result.cc);
// alert("User: " + result.name + " Cost Center = " + result.cc + '\nDepartment: ' + result.dept + ', email: ' + result.email);
}
I needed line 2 in the above, you can test using the commented-out 'alert()' there to see what is being returned.
I converted the values in the object to String. Your script include can do the same
if(grUser.next()){
obj.name = grUser.name.toString();
obj.email = grUser.email.toString();
obj.department = grUser.department.toString();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 01:36 PM - edited 04-01-2025 01:42 PM
Hello @NehaSNOW
There are two ways to achieve it:
1. onChange Catalog Client Script and Script include -- which you did however just need to make one correction in your script include and one correction in Client Script:
obj.name = grUser.getValue('name');
obj.email = grUser.getValue('email');
obj.department = grUser.getDisplayValue('department');
g_form.addInfoMessage("TEST VALUE2 " + emp.name);
g_form.setValue('employee_name', emp.name);
g_form.setValue('email', emp.email);
g_form.setValue('department', emp.department.toString());
Here are the validation results:
Before:
After:
2. The other way is to achieve it without coding i.e using Auto populate feature of the variables: The only requirement is that all these variables have to be type: Reference
An example of Employee Name Reference Type variable:
Validation Results:
Hope that helps!