Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Fetch the manager of the selected assignment group and displays the manager's name as a field mesg

Jyoti Ranjan Se
Tera Contributor

Hi Everyone,

I want to show manager of assignment group under assignment group field as field message. how can i achieve this .

please help me on this.

 

Regards

Jyoti

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Jyoti Ranjan Se 

you can use onChange client script with GlideAjax and show the field message

Something like this

Script Include: Client callable

var GroupManagerUtils = Class.create();
GroupManagerUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getManagerName: function() {
        var groupId = this.getParameter('sysparm_group_id');
        var group = new GlideRecord('sys_user_group');
        if (group.get(groupId)) {
            var manager = group.getDisplayValue('manager');
            return manager;
        }
        return '';
    },
    type: 'GroupManagerUtils'
});

onChange client script on Assignment Group field:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    if(newValue != oldValue){
    var ga = new GlideAjax('GroupManagerUtils');
    ga.addParam('sysparm_name', 'getManagerName');
    ga.addParam('sysparm_group_id', newValue);
    ga.getXMLAnswer(function(response) {
        var managerName = response;
        if (managerName) {
            g_form.showFieldMsg('assignment_group', 'Manager: ' + managerName, 'info');
        } else {
            g_form.showFieldMsg('assignment_group', 'No manager found for this group', 'info');
        }
    });
}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader