Need help modifying UI action to check if field is empty and show error message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2019 07:14 AM
Using this UI action that is calling a script include, I am trying to check if a variable on the RITM is populated. If it's empty I want to show an error message. Unfortunately I am having trouble preventing the submission if the conditions are not met
if (current.variables.request_type != ''){
var apiUtils = new ServiceRequestAPI(); //POST service request information
var workOrder = apiUtils.generateWorkOrder(); //Call script include that contains POST message
var request_type = current.variables.request_type;
current.state = 2; //set the state to in progress
current.watch_list = current.variables.trimark_csr; //add the user selected to the watchlist
current.comments = ' WO Requested';
gs.addInfoMessage(' WO Requested');
current.update();
action.setRedirectURL(current);
} else {
gs.addErrorMessage('The following mandatory fields are not filled in: Resolution);
return false;
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2019 07:53 AM
No its the default

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2019 07:29 AM
It has to be wrapped in an onSubmit function:
function onSubmit() {
if (current.variables.request_type != '--None--' && current.variables.request_type != undefined && current.variables.request_type != "undefined") {
var apiUtils = new ServiceRequestAPI(); //POST service request information
var workOrder = apiUtils.generateWorkOrder(); //Call script include that contains POST message
var request_type = current.variables.request_type;
current.state = 2; //set the state to in progress
current.watch_list = current.variables.trimark_csr; //add the user selected to the watchlist
current.comments = ' WO Requested';
gs.addInfoMessage(' WO Requested');
current.update();
action.setRedirectURL(current);
} else {
gs.addErrorMessage('The following mandatory fields are not filled in: Resolution');
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2019 07:45 AM
hi there instead of return false will you try current.setAbortAction(true);
and yes don't forget to put ending bracket
If this resolves your query, please mark my comments as correct and helpful
.
Regards,
Ajay Chavan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2019 10:22 AM
can you add the log to check what are you getting in "current.variables.request_type"
gs.log(' value is '+ current.variables.request_type);
Add the screenshot of your updated ui action .