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.

Need help with UI Policy script using Glide Ajax

HARI KISHAN GVS
Mega Sage

Hi Team,

I created one script include and one Ui Policy to make some fields readonly value false.

when i run the script include in backgroup script, it is giving me the correct values. but it's not working in UI Policy script:

Script Include:

var NRChangeUtils = Class.create();
NRChangeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getStdChgTempFields: function() {
        var sysId = this.getParameter('sysparm_sys_id');
        var chg = new GlideRecord('change_request');
        chg.addQuery('sys_id', sysId);
        chg.query();
        if (chg.next()) {
            var temp = new GlideRecord('std_change_record_producer');
            temp.addQuery('name', chg.std_change_producer_version.std_change_producer.name);
            temp.query();
            if(temp.next()) {
                var unqval = temp.getUniqueValue();
            }
			var rec = new GlideRecord('std_change_record_producer');
			if(rec.get(unqval)){
				var util = new StdChangeUtilsSNC();
				var opr = util._parseEncodedQuery(rec.template.template);
				return opr.names;
			}
        }
    },

    type: 'NRChangeUtils'
});

 UI Policy script:

policy condition is change type is Standard

in execute true used this:

function onCondition() {
    alert('ABC');
    var gr = new GlideAjax("NRChangeUtils");
    gr.addParam('sysparm_name', 'getStdChgTempFields');
    gr.addParam('sysparm_sys_id', g_form.getUniqueValue());
    gr.getXMLAnswer(response);

    function response(answer) {
        var allFields = g_form.getFieldNames();
        alert('DEF');

        for (var fieldName in allFields) {
            if (!answer.includes(fieldName)) {
                g_form.setReadOnly(fieldName, false);
                alert(fieldName);
            }

        }
    }

}

alert('ABC') is generating but alert ('DEF') is not generating.

Could anyone please fix my script?

Thanks,

Hari Kishan.

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

Use the UI Policy script in an onLoad or onChange Catalog Client Script instead, adding whatever trigger conditions to the script.