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

No its the default 

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

Chavan AP
Kilo Sage

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 find_real_file.png and helpful  find_real_file.png.

Regards,

Ajay Chavan

My Community Articles

LinkedIn

Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****

Harsh Vardhan
Giga Patron

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 .