Need help modifying UI action to check if field is empty and show error message

mdjoseph12
Giga Contributor

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;
13 REPLIES 13

Elijah Aromola
Mega Sage

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;
}

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;
}

Is this an onSubmit script?

This is the UI action script