- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2020 08:06 PM
Please help me with the script includes and onchange client script to Populate requested for details while raising a request through catalog item.
Below are the variables from catalog item.
Requested for - requested_for
Requested by - requested_by
Location- location
Reigion - reigion
Manager - manager
Email - email.
These fields need to be auto populated when the requested for changes.
Thank you,
Balaram.
Solved! Go to Solution.
- Labels:
-
Incident Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2020 10:08 PM
sample script below
I assume below
1) manager variable is reference to sys_user table
2) location variable is reference to cmn_location table
3) region variable is string type and the region field on sys_user is string type
Script Include: It should be client callable
var CheckRecords = Class.create();
CheckRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkRecordPresent: function(){
var obj = {};
var id = this.getParameter('sysparm_userID');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', id);
gr.query();
if(gr.next()){
obj['email'] = gr.getValue('email');
obj['manager'] = gr.getValue('manager');
obj['location'] = gr.getValue('location');
obj['region'] = gr.region.toString();
}
return JSON.stringify(obj);
},
type: 'CheckRecords'
});
onChange Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('CheckRecords');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_userID', g_form.getValue('requested_for_variable')); // give here your variable name
ga.getXMLAnswer(function(answer){
if(answer != 'not found'){
var parser = JSON.parse(answer);
g_form.setValue('manager_variable', parser.manager); // give here manager variable name
g_form.setValue('email_variable', parser.email); // give here email variable name
g_form.setValue('location_variable', parser.location); // give here location variable name
g_form.setValue('region_variable', parser.region); // give here region variable name
}
});
//Type appropriate comment here, and begin script below
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2020 08:42 PM
Hi Balaram,
Create client callable script include and pass requested for sysid to the script include as a parameter and glide user table to get other user information
Call script include on change or load of the form. Use glideajax to call script include and pass requested for field value to script include
See link for more details
Thanks,
RJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2020 08:45 PM
Hi Rahul,
Thanks for your response.
Please help me with the script includes syntax and on change client script. That will be helpful.
Thank you,
Balaram.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2020 08:48 PM
Hi Balaram,
Go through this link . This Article will help you for code
Let me know if you have any query
Thanks,
RJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2020 10:08 PM
sample script below
I assume below
1) manager variable is reference to sys_user table
2) location variable is reference to cmn_location table
3) region variable is string type and the region field on sys_user is string type
Script Include: It should be client callable
var CheckRecords = Class.create();
CheckRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkRecordPresent: function(){
var obj = {};
var id = this.getParameter('sysparm_userID');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', id);
gr.query();
if(gr.next()){
obj['email'] = gr.getValue('email');
obj['manager'] = gr.getValue('manager');
obj['location'] = gr.getValue('location');
obj['region'] = gr.region.toString();
}
return JSON.stringify(obj);
},
type: 'CheckRecords'
});
onChange Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('CheckRecords');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_userID', g_form.getValue('requested_for_variable')); // give here your variable name
ga.getXMLAnswer(function(answer){
if(answer != 'not found'){
var parser = JSON.parse(answer);
g_form.setValue('manager_variable', parser.manager); // give here manager variable name
g_form.setValue('email_variable', parser.email); // give here email variable name
g_form.setValue('location_variable', parser.location); // give here location variable name
g_form.setValue('region_variable', parser.region); // give here region variable name
}
});
//Type appropriate comment here, and begin script below
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader