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

a_49
Tera Contributor

Ui Policy Action execute first.

BiancaK
Tera Expert

As per the Scripting in ServiceNow Fundamentals eBook page 157 (Tokyo): "UI Policy Actions execute before UI Policy Scripts"

BiancaK_0-1694285357447.png

 

BiancaK
Tera Expert

As per the Scripting in ServiceNow Fundamentals eBook page 157 (Tokyo): "UI Policy Actions execute before UI Policy Scripts"

BiancaK_0-1694285357447.png

 

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.clearMessages();
    g_form.addErrorMessage('Execute if true');
}​

 


This tells me that the script runs before the actions.

Did you haven anything in UI Policy actions?