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.

glideajax not working

si21
Tera Guru

Hi experts,

we have a requirement, when selected user is a manger in user table, then only we need to display a variable 'should current team'.

For this I have written script include (client callable) and client script ( onchange) but some how field is not getting displayed.

PFB the code snippets and guide me where I went wrong.

Script Include:

var checkManageScript = Class.create();
checkManageScript.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    checkManager: function() {
        var selectedUser = this.getParameter('sysparam_emp');
        //query to check if user ismanager
        var userGr = new GlideRecord('sys_user');
        userGr.addQuery('manager', selectedUser);
        userGr.query();
       
        if (userGr.hasNext()) {
           
            return 'true';
        } else {
           
            return 'false';
        }
    },
    type: 'checkManageScript'
});

 

Screenshot 2024-04-12 191210.png

 

Client Script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        g_form.setDisplay('should_current_team', false);
        return;
    }
   // var mgr = g_form.getValue('workdayid');
    var ga = new GlideAjax('checkManageScript');
    ga.addParam('sysparam_name', 'checkManager');
    ga.addParam('sysparam_emp', newValue);
    ga.getXML(onResponse);
}

function onResponse(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    if (answer === 'true') {
        alert('user is  a manager');
        g_form.setDisplay('should_current_team', true);
    } else {
        alert('user is not a manager');
        g_form.setDisplay('should_current_team', false);
    }
}

 

Screenshot 2024-04-12 191325.png

Note: when ever I select a user who is manager or not, alert in the line 19 pops up.

 

TIA 

 

 

 

1 ACCEPTED SOLUTION

Okm i see it, in your client script you are using 

sysparam_name and sysparam_emp 

while it should be

sysparm_name and sysparm_emp

 

Correct the first like in your script include too where you are reading sysparm_emp

-Anurag

View solution in original post

5 REPLIES 5

dgarad
Giga Sage

Hi @si21 

change the below code in the client script.

 

   if (answer =='true') {
        alert('user is  a manager');
        g_form.setDisplay('should_current_team', true);
    } else {
        alert('user is not a manager');
        g_form.setDisplay('should_current_team', false);
    }

 

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

Thanks
dgarad