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

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Can you confirm whether or not The new Value you are sending in the client script is a sys_id or not? It should be sys_id of a user.

 

-Anurag

Hi @Anurag Tripathi , yes we are sending sys_id

 

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

Thank you so much Anurag. It's working