How to call a system property on catalog client script or UI policy?

Kirthi2
Tera Contributor

I have not written this before and fairly new to this approach on calling system property on client side scripting
and trying to understand how to call a system property on a Catalog client script? 

I have defined a system property where the Value is null. when the system property value is null then I want to display certain options.

Below is the screenshot of the client script, when the system property is null and the value of the variable 'ref_req_company' is 'XYZ company' then an option needs to display.

It's not working and not displaying the option I have given under setDisplay.

find_real_file.png

Below is the business rule where I defined g_scratchpad 

find_real_file.png

I am stuck at this point and not able to move forward. any help is greatly appreciated.

1 ACCEPTED SOLUTION

You can use below Script include.

find_real_file.png

var propertyUtil = Class.create();
propertyUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getProperty: function() {
        return gs.getProperty('catalog.csa.exclude.lead_mfs');
    },
    type: 'propertyUtil'
});

Catalog client script.

function onLoad() {
    var ga = new GlideAjax('propertyUtil'); //This argument should be the exact name of the script include. 
    ga.addParam('sysparm_name', 'getProperty'); //sysparm_name is the name of the function in the script include to call. 
    ga.getXML(myCallBack); //This is our callback function, which will process the response.

    function myCallBack(response) { //the argument 'response' is automatically provided when the callback funciton is called by the system.
        //Dig out the 'answer' attribute, which is what our function returns. 
        var prop = response.responseXML.documentElement.getAttribute('answer');
        alert(prop); //alert the result to make sure all is well.
    }
}

 

Hope it helps.

View solution in original post

6 REPLIES 6

Ujjawal Vishnoi
Mega Sage
Mega Sage

No we cant use g_scratchpad variable in this case.

g_scratchpad is an empty/temporary object you can use to push information (properties, objects, functions, custom variables etc.) from the server to the client.

Note:- that information is not available currently on the form

 You cannot run display business rules for catalog items.

scratchpad is a data holder which is on server and client side 

Server - Display Business Rule to put data in scratch pad 

Client - Read data from scratch pad and use it 

https://docs.servicenow.com/bundle/madrid-application-development/page/script/business-rules/concept...

For catalog item form or record producer you should make a GlideAjax call via client script.

@Ujjawal Vishnoi 

Thank you for clarifying this for me.

Can you please make some suggestions on how I can achieve this. I have not used the GlideAjax call in client scripts before using the system property.

can you give me some pointers on how can I get this to working.

Thanks in advance.

You can use below Script include.

find_real_file.png

var propertyUtil = Class.create();
propertyUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getProperty: function() {
        return gs.getProperty('catalog.csa.exclude.lead_mfs');
    },
    type: 'propertyUtil'
});

Catalog client script.

function onLoad() {
    var ga = new GlideAjax('propertyUtil'); //This argument should be the exact name of the script include. 
    ga.addParam('sysparm_name', 'getProperty'); //sysparm_name is the name of the function in the script include to call. 
    ga.getXML(myCallBack); //This is our callback function, which will process the response.

    function myCallBack(response) { //the argument 'response' is automatically provided when the callback funciton is called by the system.
        //Dig out the 'answer' attribute, which is what our function returns. 
        var prop = response.responseXML.documentElement.getAttribute('answer');
        alert(prop); //alert the result to make sure all is well.
    }
}

 

Hope it helps.

Thank you so much @Ujjawal Vishnoi, exactly what I was looking for.

I marked the answer as correct.