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:19 AM
Does request_type have a default value or any case where it isn't empty? You're also missing an ending bracket at the bottom of your script (not sure if it just didn't copy over). Try the following:
if (current.variables.request_type != '' && 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:25 AM
Hi Elijah -
This is the error that I am getting
could not save record because of a compile error: JavaScript parse error at line (18) column (7) problem = invalid return (<refname>; line 18)
Here's the script
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:27 AM
Is this an onSubmit script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2019 07:28 AM
This is the UI action script