
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2018 06:51 PM
I have a UI action that runs server-side to update the state of a reocrd. The script is very simple:
moveToImplemented();
function moveToImplemented(){
current.state = 2;
current.update();
action.setRedirectURL(current);
}
My question is, will this automatically validate that mandatory fields in the previous state are populated? I was always under the assumption that it did, based on testing and observation clicking the button gave me an error message if I left mandatory fields blank. However, I ask because we recently had one case where a user somehow got to this new state without populating the mandatory fields.
Actually, this user says that they did indeed fill in all the mandatory fields, and update via the UI Action button, but there is no indication in the audit history that any of those fields were ever set. I'm very confused as to how it would even be possible to leave those fields blank, as every attempt to reproduce the issue has shown the expected result.
Solved! Go to Solution.
- Labels:
-
User Interface (UI)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2018 03:28 PM
Hi Chris,
The form are being loaded on Client side and it is browser/machine/internet connection speed dependent.
E.g. Form and all local javascript component not being fully loaded before your user start typing into the fields and press submit. Loading of the form are also depends on internet connection speed as well as machine condition at that point of time.
There could be more scenario where browser screw up the data being post to server, connection timeout on client side etc...
As such, if the objective is not to end up in this state, suggest to put in additional explicit check before you update the record just to be safe.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2018 07:21 PM
One thought is to check if the field in question is maybe conditionally mandatory? It might be mandatory in certain conditions, not all the time?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2018 07:36 PM
It is mandatory with a UI Policy that checks the state. I definitely think they were mandatory, and the user says they populated these fields and I trust them. The UI policy and UI action have both been in place and unchanged for some time now, and this is the first time I have ever seen this happen.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2018 05:05 PM
Hi Chris
You can try using the before update business rule. You have two objects here current and previous.
You can put a if condition like below.
if(previous.state== 'X' && current.state== 'Y'){
If(current.FIELD_NAME1 == '' || current.FIELD_NAME2 == ''){
gs.addErrorMessage("please fill mandatory fields");
current.setAbortAction(true);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2018 09:28 PM
What I don't understand is why that business rule would be necessary? In every attempt I've made to reproduce the issue, it behaves as expected. I get "the following mandatory fields are not filled in" error without any business rules. It seems like it was an isolated occurrence. I actually even had the exact same record in a cloned test environment and it behaved as expected impersonating that user. I reported it to the customer as an isolated glitch in ServiceNow.
One thought I had was maybe they were on a different view. But it won't even let me change the view until I fill in the mandatory fields.