Which executes first ,UI policy action or UI policy script?

Rohith16
Tera Contributor

When runnning ui policies ,which executes first ,whether UI policy action or UI policy script?

26 REPLIES 26

Yes. Here is what I just now tested with:

 

RaymondTapper_1-1726174216554.png

 

 

Raymond Tapper
Tera Contributor
I tested this on the incident form in a Vancouver PDI by modifying the "Fields set to mandatory for all states" UI policy.
 
I changed the When to Apply condition to when the state was "In Progress"
I enabled Run scripts and added the following code in the Execute if true section:

 

function onCondition() {
    for (i = 0; i <= 1000; i++) {
        g_form.addErrorMessage('Count ' + i);
    }
    g_form.clearMessages();
    g_form.addErrorMessage('Execute if true');
}

 

 
When the form loads, the caller and short descriptions fields are not mandatory. When I select "In Progress" for the state, after about 5 seconds the caller and short description fields become mandatory.
 
The following code produces a similar result:

 

function onCondition() {
    for (i = 0; i <= 500000; i++) {
		g_form.clearMessages();
    }
    g_form.addErrorMessage('Execute if true');
}​

 

 

This tells me that the script runs before the actions.

Hi @Raymond Tapper  

Thanks but my response was based on what is in ServiceNow ebook. Guess ServiceNow will need to update their ebook 🙂

I completely agree. If it should match the book, then they should fix whatever is wrong.

Mahesh Baraskar
Mega Guru

@Rohith16 

 

UI Policy action executes before the UI policy script.

 

You can test it by creating UI policy on the form for a particular field, e.g. category on incident form.  In that, write UI policy script and create one UI Policy action.  Then, go to Preferences->Developers->Click on JS Log and Field watcher, make it true.  Then, you can Field Watch the category on incident form.  You will see the execution order clearly in Field Watcher. 

 

You can refer to the screenshot attached herewith.

UI policy.PNG