Evaluate UI Policies in a script

gflewis
Kilo Expert

Is it possible to write a script that evaluates UI policies for the current record, returning true if all mandatory fields are completed and false if mandatory fields are blank?

I need to make the "State" field on my "Change Request" form read-only, and require users to click a button (UI Action) to advance the ticket to the next state. However, I only want the button to be visible if all UI policies are satisfied. We have made a lot of extensions to our Change Request form, and there are a lot of UI policies. I am now faced with the prospect of duplicating all this logic in the "Condition" field of my UI Action. Is there an easier way?

5 REPLIES 5

Chris_Hann
ServiceNow Employee
ServiceNow Employee

I'd also echo Tony's warning about excessive or non-performant UI Policies / Client Scripts, you can also use



g_form
to determine whether all mandatory fields are populated, see below:



var hasNoMissingFields = g_form.getMissingFields().length == 0;


tony_fugere
Mega Guru

First off, be careful with "a lot of UI policies", this can really bog down the user experience. Be sure you minimize/optimize them.

Second, ignore what was here and go with Chris's


g_form.getMissingFields().length
call instead. Much smarter way.


gflewis
Kilo Expert

g_form.getMissingFields() is cool.

However, I was originally looking for was a server-side equivalent of this function. I was going to go with a server UI action because I have some other processing that needs to happen when the state changes. If I go with a client UI action then I need to either (a) move the other processing into the client script, or (b) split the processing between client UI action and a business rule. Also, I think the client script can only modify fields that appear on the form and are editable by the user, whereas the server script has no such limitation.

If there were a server equivalent of this function, then I could just add the following condition to my server UI action and I would be home free.



getMissingFields(current).length == 0


Any thoughts?


I don't think the server side is going to be able to detect that... The user isn't going to be able to submit the form if mandatory fields are blank?????