Need help with UI Policy script using Glide Ajax

Not applicable

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.

3 REPLIES 3

Brad Bowman
Mega Patron

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

kevinbruneau
Tera Contributor

Hi Hari, did you find a solution for this? I am facing the same issue

Hello @kevinbruneau 

My recommendation would be to open a new community thread for the same and be as much as descriptive as possible and avoid sharing any personal/professional information in your post.

Some best practices are:
1. For asynchronous calls, Client script calling Script Include with Glide AJAX enabled checked is preferable.

2. When returung results from Script Include in such scnearios, then return String by using  .toString().


Hope that helps!