Client script for manager's manager

User_267
Tera Contributor

We have two fields- user ,  manager's manager.

In user field - if we enter abel tutor name approval will trigger to Abel tutor manager.ex: abhraham lincoln (configured through flow)

In manager's manager field- it should be trigger to abhraham lincoln manager.

Need client script for this. It should autopopulate manager's manager based on user field.

6 REPLIES 6

Hello ankur, I have script to autopopulate manager name. Attached that screenshot.but I don't know to modify for manager's manager name

Sumanth16
Kilo Patron

Hi @User_267 ,

 

Please make changes to below script as per your requirement:

Script Include: make sure Client callable is set to true on your Script Include

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

    getUserManager: function() {
        var manager_name = '';
        var userID = this.getParameter('sysparm_caller_id');

        var userGR = new GlideRecord("sys_user");
        if (userGR.get(userID)) {
            manager_name = userGR.getDisplayValue("manager");
        }
        return manager_name;
    },
    type: "GetUserCustomUtils"
});

Create onchange client script Client script:

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

    var ga = new GlideAjax('GetUserCustomUtils');
    ga.addParam('sysparm_name', 'getUserManager');
    ga.addParam('sysparm_caller_id', g_form.getValue('caller_id'));
    ga.getXMLAnswer(parseResponseData);
}

function parseResponseData(response) {
    var managerName = response;
    g_form.setValue('short_description', managerName);
}

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda