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.

UI Action to Check for Mandatory fields before Updating State

Mrman
Tera Guru

Hi All,

I have requirement to update the state using the UI action and this UI action should update the state only when Mandatory fields are getting populated . 

This is UI action is making state to 'Closed' and we have UI policy to make certain fields mandatory when state changes to Closed .

So this UI action should not be updating the state with out checking for Mandatory fields.  

Below UI action created with client checkbox selected , this is not working .

function movearbitration() {

    //Call the UI Action and skip the 'onclick' function
    gsftSubmit(null, g_form.getFormElement(), 'hr_labor_arbitration'); //MUST call the 'Action name' set in this UI Action
}

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
    if ((g_form.getValue('u_resolution_code') != '') && (g_form.getValue('u_resolution_description') != '') && (g_form.getValue('u_precedent') != '')){
        runArbitrationcode();

function runArbitrationcode() {
    current.state = 3;
    current.update();
    gs.addInfoMessage('Labor case has been moved to arbitration');
    action.setRedirectURL(current);

} 
	}

else{
	gs.addErrorMessage("Please fill in mandatory fields");
}
13 REPLIES 13

@Ashley Snyder  , @Muhammad 

 

Could you please guide .

We cannot redirect to a particular field. Users have to manually navigate to those fields to fill in. 

You can display an error message based on empty value that these fields are not filled in. 

g_form.addErrorMessage("Please enter Resolution code..........."));

use the above line in the client-side of UI action before "return".

Regards,
Muhammad

Thanks @Muhammad I updated that code for future reference.

Sounds Good!

Regards,
Muhammad