- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2015 10:39 PM
Hi,
Can anyone help please.
I have a reference field(sys_user) in incident . When a user is selected automatically the other field (u_user_manager) should populate the manager of the user.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2015 11:36 PM
You need to have a Client Script as:
- function onChange(control, oldValue, newValue, isLoading, isTemplate) {
- if (isLoading || newValue == '') {
- return;
- }
- var user = g_form.getReference('<<fieldname>>');
- g_form.setValue('u_user_manager', user.manager);
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2015 09:59 PM
OK.
It is resolved via Script include. Now it works fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2017 12:26 PM
The above answers did not work for me. To get manager name of a user onChange use GlideAjax:
Write the onChange function as follows:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
else
{
var ga = new GlideAjax('ScriptLibrary');//This is the name of your script include, make it client callable
ga.addParam('sysparm_name','getUserManager');//This is your function in the script include
ga.addParam('sysparm_user_name', newValue);//newValue is the user sys id--it must come from a reference field
ga.getXML(GetParse);
}
function GetParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('corresponding_manager', answer);//corresponding_manager is the field name that will be updated
}
}
server side script include needs to be as follows:
var ScriptLibrary = Class.create();
ScriptLibrary.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getUserManager: function() {
var parent=new GlideRecord('sys_user');
var id=this.getParameter('sysparm_user_name');
parent.addQuery('sys_id', id);
parent.query();
parent.next();
return parent.manager;
},

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2019 07:39 AM
Consider using the strict comparison operator === instead of == in your boolean condition.