GlideAjax call returning "null" for customer users

Prem5
Tera Contributor

Hi all,

 

I have an On-Change client script that makes a Glide Ajax call and returns a value. The script include which is being called has a function with simple script making a Glide record on Sold Product(sn_install_base_sold_product).

 

The script is working fine when logged in as an admin, but when logged in as a customer it is returning "null". I figured it may be an issue with the Query rules as we have OOTB CSM query rules on Sold product table. I created a new query rule to provide read access for a particular customer role, but still the script is returning "null". Any leads or help with the troubleshooting of this issue is appreciated.

 

Attaching my client script and script include code for reference.
Client Script:

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

function ajaxCallserial() {
    var serialNumber = g_form.getValue('product_key');
    var numCheck = new GlideAjax('global.ClaimProductUtilsAjax');
    numCheck.addParam('sysparm_name', 'validateSerialNumber');
    numCheck.addParam('sysparm_serialNumber', serialNumber);
    numCheck.getXML(handleResponse);

    function handleResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
		alert(answer);
        if (answer == 'false') {
            g_form.setValue('response_variable', "false");
        } else{
            g_form.setValue('response_variable', "true");
		}
    }
}

 Script Include:

 validateSerialNumber: function() {
        var serialnumber = this.getParameter('sysparm_serialNumber');
		
        var checkNum = new GlideRecord('sn_install_base_sold_product');
        checkNum.addQuery('u_sold_product_serial_number', serialnumber);
        checkNum.query();
        if (checkNum.hasNext()) {
            return true;
        } else return false;

    },
1 ACCEPTED SOLUTION

Vishal Birajdar
Giga Sage

Hi @Prem5 

 

In script include , Can you try by adding below function in script include :

 

isPublic:function(){
return true;
},

Foe example : 

/*For example */

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

isPublic:function(){
return true;
},

/*your function */
validateSerialNumber: function() {
        var serialnumber = this.getParameter('sysparm_serialNumber');
		
        var checkNum = new GlideRecord('sn_install_base_sold_product');
        checkNum.addQuery('u_sold_product_serial_number', serialnumber);
        checkNum.query();
        if (checkNum.hasNext()) {
            return true;
        } else return false;

    },


   type: 'yourScriptIncludeName';
});

 

Below link might help : 

https://docs.servicenow.com/en-US/bundle/vancouver-platform-security/page/administer/security/refere...

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

5 REPLIES 5

Shruti
Mega Sage
Mega Sage

Hi,

Check if there is any ACL 

Operate - execute

Type - client_callable_script_include

Name - name of Script include

 

Add required roles to the ACL

Prince Arora
Tera Sage
Tera Sage

@Prem5 

 

Issue is with the ACL, when we created a new client callable script include there is an ACL(operation -execute) associated with it.

Please check what role is added to that ACL, that roles should be available to the end user OR you can add another role to the ACL(the same role which customer has) to made it accessible to the end user or customer.

 

 

Vishal Birajdar
Giga Sage

Hi @Prem5 

 

In script include , Can you try by adding below function in script include :

 

isPublic:function(){
return true;
},

Foe example : 

/*For example */

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

isPublic:function(){
return true;
},

/*your function */
validateSerialNumber: function() {
        var serialnumber = this.getParameter('sysparm_serialNumber');
		
        var checkNum = new GlideRecord('sn_install_base_sold_product');
        checkNum.addQuery('u_sold_product_serial_number', serialnumber);
        checkNum.query();
        if (checkNum.hasNext()) {
            return true;
        } else return false;

    },


   type: 'yourScriptIncludeName';
});

 

Below link might help : 

https://docs.servicenow.com/en-US/bundle/vancouver-platform-security/page/administer/security/refere...

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Hi @Vishal Birajdar, thank you for your input. This worked like a charm