UI Policy does not apply on Service Portal

dennismagnuson
Kilo Expert

I have a new table with two fields. Main field is a choice based on the Country field from the Location table. Client I'm working with isn't using default values, importing from external source, so need to get actual values from records and show those as choice options. On new table I'm using a UI Policy to make fields read only once both are selected, but conditions are false, use run script to populate list. Everything looks fine in Desktop UI, but Portal acts as if it's not processing UI Policy. Client is limiting Platform UI to admin and itil roles, so users updating/adding records should be using the Service Portal.

What's weird is that in my Orlando PDI, this works just fine, but in my New York one, it's acting the same as client's NY instance. When opening the table via the list portal page, everything works fine. However, when you open a record and it opens in the form portal page, Orlando processes the UI Policy correctly, but NY doesn't. The NY instance gives a Warning message when viewing the console log.

js_includes_sp.jsx?v=04-10-2020_1401&lp=Wed_Jun_03_08_06_06_PDT_2020&c=23_468:31531 UI Script does not return an object or function: ConditionalFocus

The UI Policy script is set to Run scripts in UI type = All. The script calls a GlideAjax and per HI KB, the additional function for the callback was placed in the getXML. Here's the UI Policy script for Execute if False.

function onCondition() {
    //Type appropriate comment here, and begin script below
    g_form.clearOptions('u_country');

    //lookup existing values
    var ga = new GlideAjax('SWUtils');
    ga.addParam('sysparm_name', 'getCountries');
    ga.getXML(function countryList(response) {
        g_form.addOption('u_country', '', '--None--');
        var answer = response.responseXML.documentElement.getAttribute("answer").split(',');
        for (var i = 0; i < answer.length; i++) {
            g_form.addOption('u_country', answer[i], answer[i]);
        }
    });
}

Again, not an Issue in an Orlando instance, but showing up in New York Patch 8. All g_form functions are Portal capable per docs.

Any thoughts or suggestions appreciated.

Adding script include being called.

var SWUtils = Class.create();
SWUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getCountries: function() {

        var cntry_array = [];

        var cntry = new GlideRecord('cmn_location');
		cntry.orderBy('country');
        cntry.query();
        while (cntry.next()) {
            if (cntry.country != '') {
                cntry_array.push(cntry.country + '');
            }
        }

        var arrayUtil = new ArrayUtil();
        cntry_array = arrayUtil.unique(cntry_array);

        return cntry_array.toString();

    },

    type: 'SWUtils'
});
1 ACCEPTED SOLUTION

dennismagnuson
Kilo Expert

Well, good news is that we're not crazy, this is an actual problem per ServiceNow found in New York and fixed in Orlando. They provided link to KB article on HI which says to "Wrap the script (the affected UI script) inside a self-invoking function...". 

I didn't think it would work for either the Client Script or the UI Policy script as both have pre-defined function calls. I tried it anyways and got an error.

Here's the link to the article, but seems to be something that will need to be addressed with Orlando or above. https://hi.service-now.com/kb_view.do?sysparm_article=KB0748990

Thanks,

Dennis

View solution in original post

6 REPLIES 6

Allen Andreas
Administrator
Administrator

Hi,

Yea, definitely odd with the issue showing up in New York versus Orlando, but there are cases where SN has changed how the scripts are processed which leads to wonky results like this.

A few things:

1) This is pulling ALL country fields from ALL location records. Is this needed? So...duplicates? And it varies that much that you need to do this?

2) Can you try using client script? Just to see if the behavior is the same?

UI Policies are nice and should definitely be used first, but if you could work out the same condition, even if just for the script portion, can you try that since the UI Policy is acting odd?

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Allen,

Started with client script and then moved to UI Policy when I wanted the fields to be read only once selected. Same result with either.

It does only return unique values for the country choices as it pushes into an array.

Yeah, I'm at a lose on the difference between NY and Orlando. Couldn't find anything in the Patches or searching HI.

Thanks,

Dennis

Oh, yea, sorry, I see the unique there in the array Util.

As far as setting fields read only, you can still let the UI Policy take care of that, but the Client Script could help this process.

Can you try using client script of:

var ga = new GlideAjax('SWUtils');
ga.addParam('sysparm_name', 'getCountries');
ga.getXML(getValues);

function getValues(response) {
g_form.addOption('u_country', '', '--None--');
var answer = response.responseXML.documentElement.getAttribute("answer");
alert("The answer is: " + answer); //just to see how it comes back, if the split is necessary, etc.
for (var i = 0; i < answer.length; i++) {
g_form.addOption('u_country', answer[i], answer[i]);
 }
}

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

So I originally started with the Client Script process and that's when I first encountered the issue. Same code on either, but same result.