- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2023 12:33 PM
In incident form if i change a caller field his information i.e department, mail, manager, phone number should be auto populate in description field.
I need to store values/push values in string and them have to get same array to CS and then set description to as string.
Any inputs? I am unable to store values in string and set same string to description through client script?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 03:25 AM
Hello @KM SN ,
Hope you are well !
Please create a Client callable Script Include and Client Script. For your reference please find below script :
Script Include :
returnEmployeeDetails: function() {
var data = '';
var employee = this.getParameter('sysparm_user');
var grEmployee = GlideRecord('sys_user');
grEmployee.addQuery('sys_id', employee);
grEmployee.query();
while (grEmployee.next()) {
data = grEmployee.first_name + ',' + grEmployee.last_name + ',' + grEmployee.email + ',' + grEmployee.title + ',' + grEmployee.location;
return data;
}
},
Client Script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var employee = g_form.getValue('employee');
if (employee != '') {
var gr = new GlideAjax('ICClientCallableScriptInclude');
gr.addParam('sysparm_name', 'returnEmployeeDetails');
gr.addParam('sysparm_user', employee);
gr.getXML(getResponse);
} else {
g_form.clearValue('first_name');
g_form.clearValue('last_name');
g_form.clearValue('email');
g_form.clearValue('employee_job_title');
g_form.clearValue('location');
}
function getResponse(response) {
var values = response.responseXML.documentElement.getAttribute('answer').toString().split(',');
g_form.setValue('description', values[0] + values[1] + values[2] + values[3] + values[4]);
}
}
Please mark my answer helpful and accept the solution.
Appreciate your help !
Thank you.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2023 02:01 PM
Hi, if you need to do populate this data into the form UI then you would normally use GlideAjax to retrieve the data you need.
GlideAjax | ServiceNow Developers
It is possible to use getReference() (or GlideRecord) but neither of these are recommended best practice.
GlideForm | ServiceNow Developers
GlideRecord | ServiceNow Developers
If the data does not need to be visible to the user immediately\onChange and is not used\referenced in the UI form, then another solution would be to use an on before BR to populate the correct values when the record is saved\updated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2023 05:25 PM
Check this out:
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 03:25 AM
Hello @KM SN ,
Hope you are well !
Please create a Client callable Script Include and Client Script. For your reference please find below script :
Script Include :
returnEmployeeDetails: function() {
var data = '';
var employee = this.getParameter('sysparm_user');
var grEmployee = GlideRecord('sys_user');
grEmployee.addQuery('sys_id', employee);
grEmployee.query();
while (grEmployee.next()) {
data = grEmployee.first_name + ',' + grEmployee.last_name + ',' + grEmployee.email + ',' + grEmployee.title + ',' + grEmployee.location;
return data;
}
},
Client Script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var employee = g_form.getValue('employee');
if (employee != '') {
var gr = new GlideAjax('ICClientCallableScriptInclude');
gr.addParam('sysparm_name', 'returnEmployeeDetails');
gr.addParam('sysparm_user', employee);
gr.getXML(getResponse);
} else {
g_form.clearValue('first_name');
g_form.clearValue('last_name');
g_form.clearValue('email');
g_form.clearValue('employee_job_title');
g_form.clearValue('location');
}
function getResponse(response) {
var values = response.responseXML.documentElement.getAttribute('answer').toString().split(',');
g_form.setValue('description', values[0] + values[1] + values[2] + values[3] + values[4]);
}
}
Please mark my answer helpful and accept the solution.
Appreciate your help !
Thank you.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2023 12:16 PM
Any other alternative for storing values into array and then setting same in description through client script?