Fetch manager name from assignment group and show as field message

Jyoti Ranjan Se
Tera Contributor

Hi Everyone,

 

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

 var fetchmanager = g_form.getReference('assignment_group', getManager);

}

function getManager(fetchmanager) {
    //var ManagerName =fetchmanager.manager.name;
    //g_form.showFieldMsg('assignment_group',fetchmanager.ManagerName);
    g_form.showFieldMsg('assignment_group', 'Change Manager: ' + fetchmanager.manager, 'info');
   
}
 
I have written this code for it and it comes with sysid can you please help me to display manager name.
Also is have tried this script as well 
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

 var fetchmanager = g_form.getReference('assignment_group', getManager);

}

function getManager(fetchmanager) {
    //var ManagerName =fetchmanager.manager.name;
    //g_form.showFieldMsg('assignment_group',fetchmanager.ManagerName);
    g_form.showFieldMsg('assignment_group', 'Change Manager: ' + fetchmanager.manager.name, 'info');
   
}
Result ---Undefined

please assist me on this asap

Regards
Jyoti
9 REPLIES 9

dgarad
Giga Sage

Hi @Jyoti Ranjan Se 

 

Refer the below link,

https://www.servicenow.com/community/sysadmin-forum/need-a-script-to-check-assignment-group-manager-...

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Bhavya11
Kilo Patron

Hi @Jyoti Ranjan Se ,

 

I would recommend making a glide ajax call instead since the getReference isn't something that is recommend and best practice.

 

Example one

Client script :

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

   var ga = new GlideAjax('GetUserDetails'); // script include name
ga.addParam('sysparm_name', 'getManger'); // funcation name in script include
ga.addParam('sysparm_sys_id', newValue); 
ga.getXMLAnswer(function(response) {
var userDetails = JSON.parse(response); 
     g_form.showFieldMsg('assignment_group', 'Change Manager: ' + userDetails.manager, 'info');
});   
}

 

Script include: client callable true

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

    getManger: function() {
        var userId = this.getParameter('sysparm_sys_id'); // Get the Sys ID from the client script
        var result = {};
        if (userId) {
            var userGR = new GlideRecord('sys_user_group'); // Query the sys_user_group table
             userGR.addQuery('sys_id',userId);
			 userGR.query();
			 if(userGR.next()){

				gs.log("getManger"+userGR.manager)
                result.manager = userGR.manager.getDisplayValue();
            }
        }
        return JSON.stringify(result);
    },
    type: 'GetUserDetails'
});

 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Thanks,

BK

Runjay Patel
Giga Sage

Hi @Jyoti Ranjan Se ,

 

You can configure form and do dot walking to display manager.

RunjayPatel_0-1734588016383.png

 

Else you can go ahead with ajax call as suggested by @Bhavya11 .

 

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

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

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

 

Jyoti Ranjan Se
Tera Contributor

JyotiRanjanSe_0-1734942808092.png

This is the output getting after written above script. please help me or assist