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.

gs.getProperty not working in UI script

Rosy14
Kilo Sage

Hi

I want to get the sys_ids stored in a property. Also, tried to create glide ajax to get sys_id in UI script. None is working.

Any idea how to do it by gliderecord in ajax.

(function() {
var ids = [];
        var ga = new GlideAjax('sn_csm_uni_theme.CheckUserLoggedIn');
        ga.addParam('sysparm_name', 'public_catalogs');
        var x;
        ga.getXMLAnswer(function(response) { // Use callback function
            x = response;
            if (window.location.href.toString().indexOf("sc_cat_item&sys_id") > 0) {
                var url = window.location.href;
                url = url.replace('sc_cat_item&sys_id', x);
                window.location.assign(url);
            }
		});
var CheckUserLoggedIn = Class.create();
CheckUserLoggedIn.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
 
        public_catalogs: function() {
            var ids = [];
            var gr = new GlideRecord("sc_cat_item_user_criteria_mtom");
            gr.addEncodedQuery("user_criteria.nameLIKEAny User^sc_cat_item.active=true");
            gr.query();
            while (gr.next()) {
                ids.push(gr.sc_cat_item.sys_id.toString());
            }
    		return  ids;
        },
    type: 'CheckUserLoggedIn'
});
12 REPLIES 12

Rohit  Singh
Mega Sage

Hi @Rosy14 ,

 

In script include replace: 

return "ids";

With

return ids;

 

 

If my response helped, please hit the Thumb Icon and accept the solution so that it benefits future readers.

 

Regards,
Rohit

 

actually that text msg also not returning.  i just want to test so I added in quotation

Ankur Bawiskar
Tera Patron
Tera Patron

@Rosy14 

you are returning array of sysIds, but in UI script you are replacing it here

but here only 1 sysId can be taken

                url = url.replace('sc_cat_item&sys_id', x);

if you want only 1 sysId then use this

    		return  ids[0].toString();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I just want to test if it returning the whole array or not.. thats why I added like that. but anything is not returning.