populate caller id manager name in the short description
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 03:50 AM
i have to populate caller id manager name in the short description field in incident using glide Ajax and script include.
Please provide the code for onchange CS and SI as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 03:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 04:08 AM
SI-------------------
var Getusermngr = Class.create();
Getusermngr.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getusrmngr: function() {
var user_info = '';
var userid_value = this.getParameter('getif from your CS');
//Validating User manager
var user_rec = new GlideRecord('sys_user');
user_rec.addQuery('user_name', userid_value);
user_rec.query();
if(user_rec.next()){
user_info = user_rec.manager.DisplayValue()
}
return user_info;
},
CS--------------------------------------
var result = response.responseXML.documentElement.getAttribute('answer');
if (result) {
g_form.setValue('your field', result, );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 04:09 AM
It should be a simple task.
Did you go through GlideAjax documentation?
what did you start with and where are you stuck?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 04:13 AM
Hi @showsid02,
Script Include:
var TestingScript= Class.create();
TestingScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {
populateFields : function(){
var callerID = this.getParameter('sysparm_callerID');
var user = new GlideRecord('sys_user');
var result = {};
if(user.get(callerID)){
result.caller_id = user.name.toString(); // get full name
result.manager = user.manager.name.toString(); // get manager full name
}
return JSON.stringify(result);
},
type: 'TestingScript'
});
Client Script
Type : Onchange
Field : Caller
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var sd = g_form.getValue('short_description');
var ga = new GlideAjax('TestingScript');
ga.addParam('sysparm_name','populateFields');
ga.addParam('sysparm_callerID',g_form.getValue('caller_id'));
ga.getXML(callBack);
function callBack(response){
var answer = response.responseXML.documentElement.getAttribute('answer');
var data = JSON.parse(answer);
// adding the caller and manager in short description at last
g_form.setValue('short_description',sd+'( Caller ID : '+data.caller_id+' and Manager : '+data.manager+')');
}
}
If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.
Regards,
T Mohan.