0% found this document useful (0 votes)
5 views

populate 6 fields on Incident service now

The document contains a script for a ServiceNow client-side function that populates three fields based on the caller's information when a change occurs. It utilizes GlideAjax to fetch the caller's email, manager details, and location details from a Script Include named 'IncidentCaller'. Additionally, it includes UI action code to populate more fields related to incidents and group membership for the caller.

Uploaded by

iamehtesham0901
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

populate 6 fields on Incident service now

The document contains a script for a ServiceNow client-side function that populates three fields based on the caller's information when a change occurs. It utilizes GlideAjax to fetch the caller's email, manager details, and location details from a Script Include named 'IncidentCaller'. Additionally, it includes UI action code to populate more fields related to incidents and group membership for the caller.

Uploaded by

iamehtesham0901
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

== On Change Client Script to populate 3 fields from script only

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

if (isLoading || newValue === '') {

return;

var ga = new GlideAjax('IncidentCaller');

ga.addParam("sysparm_name" ,"getEmail");

ga.addParam('callerId',newValue);

ga.getXMLAnswer(callback);

function callback(res){

var ans = res.toString().trim();

g_form.setValue("u_f1", ans);

var ga1 = new GlideAjax('IncidentCaller')

ga1.addParam('sysparm_name','callerDetail');

ga1.addParam('callerId',newValue);

ga1.getXMLAnswer(callback1);

function callback1(ress){

var answ = ress.toString().trim();

g_form.setValue("u_f2", answ);

var ga2 = new GlideAjax('IncidentCaller')

ga2.addParam('sysparm_name','managerDetail');

ga2.addParam('callerId',newValue);

ga2.getXMLAnswer(callback2);

function callback2(response){

var answer = response.toString().trim();

g_form.setValue("u_f3", answer);

}
== Script Include for populating 3 fields which will be populating on clicking UI action

var IncidentCaller = Class.create();

IncidentCaller.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getEmail : function(){

var id = this.getParameter("callerId");

var gr = new GlideRecord('sys_user');

gr.addQuery('sys_id' , id);

gr.query();

if(gr.next()){

var email_manager = gr.manager.email;

var email_caller = gr.email;

var str_rtn = "Caller's Email is "+email_caller +"Manager's Email is "+email_manager;

return str_rtn;

},

managerDetail : function(){

var id = this.getParameter("callerId");

var gr = new GlideRecord('sys_user');

gr.addQuery('sys_id' , id);

gr.query();

if(gr.next()){

// var loc = gr.manager.location;

var m_city = gr.manager.location.city;

var m_country = gr.manager.location.country;

var m_zip = gr.manager.location.zip;

// var lGr = new GlideRecord('cmn_location');

// lGr.addQuery('location')

var str = "Manager's City is "+m_city+"Country is "+m_country+"Zip is "+m_zip;


return str;

},

callerDetail : function(){

var id = this.getParameter("callerId");

var gr = new GlideRecord('sys_user');

gr.addQuery('sys_id', id);

gr.query();

if(gr.next()){

var c_city = gr.location.city;

var c_country = gr.location.country;

var c_zip = gr.location.zip;

var str = "Caller's City is "+c_city +" Country is "+c_country+"Zip is "+c_zip;

return str;

},

incidentsByUser : function(){

var details = " ";

var id = this.getParameter('callerId');

var incGr = new GlideRecord('incident');

incGr.addQuery('caller_id', id );

incGr.query();

while(incGr.next()){

details += incGr.number.toString() + " : " + incGr.short_description.toString() + " , ";

return details;

},
callerInGroup : function(){

var id = this.getParameter('callerId');

var ans = " ";

var grGr = new GlideRecord('sys_user_grmember');

grGr.addQuery('user' , id);

grGr.query();

while(grGr.next()){

ans = ans + grGr.group.name.toString() + ",";

return ans;

},

userIsAssigned : function(){

var id = this.getParameter('callerId');

var ans = " ";

var usGr = new GlideRecord('incident');

usGr.addQuery('assigned_to',id);

usGr.query();

while(usGr.next()){

ans = ans + usGr.number.toString() + ",";

return ans;

},

type: 'IncidentCaller'

});
== UI Action Demo
== Execute Function Code

function execute(){

var ga = new GlideAjax('IncidentCaller');

ga.addParam('sysparm_name','incidentsByUser');

ga.addParam('callerId',g_form.getValue("caller_id"));

ga.getXMLAnswer(callback);

function callback(response){

////var ans = response.responseXML.documentElement.getAttribute("ans");

// var tojson = JSON.parse(ans);

//console.log(tojson);

console.log(response);

g_form.setValue("u_f4",response);

var ga1 = new GlideAjax('IncidentCaller');

ga1.addParam('sysparm_name' , 'callerInGroup');

ga1.addParam('callerId' , g_form.getValue('caller_id'));

ga1.getXMLAnswer(callback1);

function callback1(res){

//var answer = res;

//console.log( answer);

g_form.setValue('u_f5', res);

var ga2 = new GlideAjax('IncidentCaller');

ga2.addParam('sysparm_name', 'userIsAssigned');

ga2.addParam('callerId', g_form.getValue('caller_id'));

ga2.getXMLAnswer(callback2);

function callback2(resp){

g_form.setValue('u_f6' , resp);

}
}

You might also like