Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

End task with ui action

jkelvynsant
Tera Contributor

Hello, community. I created 3 custom fields in a task table and in it I have the "Close task" UI action. I can only close the task when all three fields are filled in. I can save without all of them being filled in, but I can't close the task. I thought of something like this: 

 

 

if (current.short_description == 'XXX') {

if (gs.nil(current.u_invoice_id)) {
gs.addErrorMessage('ERROR');
action.setRedirectURL(current);
return false;
}

if (gs.nil(current.u_creation_date)) {
gs.addErrorMessage('ERROR');
action.setRedirectURL(current);
return false;
}

if (gs.nil(current.u_task_status)) {
gs.addErrorMessage('ERROR');
action.setRedirectURL(current);
return false;
}
}

2 REPLIES 2

surajit3
Tera Expert

Dont use action.setredirecturl it is refreshing the page and allowing the values to be save without the validation being run, 

Kirby R
Kilo Sage

@jkelvynsant . 

 

Try to add current.setAbortAction(true); before action.setRedirectUrl.

 

Hope this helps.