Array is returning null

tsoct
Tera Guru

The script include will return the stringify value shown below.

*** Script: JSON.stringify(obj): ["ABC","AF","EFD","CGED","AAAA","BBBB","CCCC","ZZZZZ",""]

 

I want  value above to appear in a Select Box type of catalog variable. The catalog client script below returns null as an answer. What could have gone wrong?

 

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

    var gb = new GlideAjax('ORGANIZATIONAjazUtils');
    gb.addParam('sysparm_name', 'getName');
    gb.getXML(getResponse);

    function getResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert("Answer: " + answer); //null is returned
        var array = answer.split(',');
        for (var i = 0; i < array.length; i++) {
            g_form.addOption('client_company_name', array[i].toString(), array[i].toString());
        }
    }

}

 

1 ACCEPTED SOLUTION

KevinBellardine
Kilo Sage

Hey @tsoct 

 

I've gone through this in my own PDI, and the only way I was able to replicate what you're seeing was if the user triggering the change didn't have the role for the script include. Have you checked the SI ACL?

View solution in original post

11 REPLIES 11

Are you getting the script value when the variable is changed - so you know for sure that this onChange Catalog Client Script is triggering this Script Include?  Is the SI Client callable?

yes correct. SI's client callable is checked.

@tsoct 

 

Are you getting the log for this 

gs.log("Return: " + obj.join(','));

 

Hoping your script include is created in Global scope as gs.log does not work in custom scope. Also while returning can u try something like this

return JSON.stringify(obj.join(','));

 

Thanks,

Danish

Hello @Danish Bhairag2 , yes, all in Global scope

("Return: " + obj.join(','));

The above is returning :

ABC,AFG,AFD,AFCD,AFCND

 

JSON.stringify(obj.join(','));

The above is returning:

"ABC,AFG,AFD,AFCD,AFCND"

Both return null in catalog client script. and a red alert 

There is a JavaScript error in your browser console 

The error message explains the null return.  Post the entire Script Include.