I want to populate the manager details in the incident form when i choose the caller it should be auto populate in the manager filed.

alokgupta
Kilo Explorer

I want to populate the manager details in the incident form when i choose the caller it should be auto populate in the manager filed.

 

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Alok,

 

Refer the OOTB script which populates Location field based on Caller and then create the similar script to populate Manager field.

https://YOURINSTANCENAME.service-now.com/sys_script_client_list.do?sysparm_query=sys_class_name%3Dsys_script_client%5EtableSTARTSWITHincident%5EnameLIKElocation%5Ename%3D(BP)%20Set%20Location%20to%20User

 

-Pradeep Sharma

View solution in original post

4 REPLIES 4

AshishKM
Kilo Patron
Kilo Patron
Hi Alok, Create a business rule on incident table. When to Run : Insert Set : Manager is Caller.Manager Thanks, Ashish Please mark correct/helpful for others if it helps you.

Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Alok,

 

Refer the OOTB script which populates Location field based on Caller and then create the similar script to populate Manager field.

https://YOURINSTANCENAME.service-now.com/sys_script_client_list.do?sysparm_query=sys_class_name%3Dsys_script_client%5EtableSTARTSWITHincident%5EnameLIKElocation%5Ename%3D(BP)%20Set%20Location%20to%20User

 

-Pradeep Sharma

Nikhil Pandit
Mega Guru

Hi Alok

You can write on change client script to get the value of manager using script include(make sure client callable checkbox true) or you can directly use dot walking using form layout.

Script include

-----------------

var GetManager = Class.create();
GetManager.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getManager: function() {
var userRecord = new GlideRecord("sys_user");
userRecord.get(this.getParameter('sysparm_userID'));
return userRecord.manager.name + '';
},

type: 'GetManager'
});

 

Client script

----------------------------

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}


var getManager = new GlideAjax('GetManager');

getManager.addParam('sysparm_name','getManager');

getManager.addParam('sysparm_userID', g_form.getValue('caller_id'));

getManager.getXML(populateManagerField);



function populateManagerField(response){

var managerFromScriptInclude = response.responseXML.documentElement.getAttribute("answer");
g_form.clearValue('u_manager');
g_form.setValue('u_manager',managerFromScriptInclude);
}

}

kushal Tayade
Mega Guru

Here You go:

 

find_real_file.png

 

function onChange(control, oldValue, newValue, isLoading) {
if ((isLoading && !g_form.isNewRecord()) || (g_form.isLiveUpdating && g_form.isLiveUpdating()))
return;

if (newValue == '' || newValue == null) {
g_form.setValue('u_manager', ''); //Your manager field name
return;
}
if (!g_form.hasField('u_manager'))
return;
var caller = g_form.getReference('caller_id', setManager);
}

function setManager(caller) {
if (caller)
g_form.setValue('u_manager', caller.manager);
}