How to make a field mandatory through Server side code within a UI action

VIKAS MISHRA
Tera Contributor

I just wanted to make a field mandatory thorugh a code within UI acton, but  do not want to use client side code there like g_Form.setMandatory(), Please suggest what is the sever side code i can use there and make a field manadtory .

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I would prefer using client side code in UI action so that user knows which field is mandatory.

you cannot make field mandatory from server side as that has to run on client side.

but what you can do is this

1) check the field value is empty or not in server side

2) if empty then throw error that field is not populated

Something like this

if(current.field == ''){
	gs.addErrorMessage("You should fill the field value for field name");
	current.setAbortAction(true);
	action.setRedirectURL(current);
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ivan Betev
Mega Sage
Mega Sage

Hello Vikas,

I think that is not possible via the server side, however you can try it with Data Policies as described here:

How to Make field mandatory with business rule and UI action ? - Developer Community - Question - Se...

Regards, Ivan

Yousaf
Giga Sage

Hi,

From what i understand you can use. Something like to this with the condition and error message 

current.setAbortAction(true);
ction.setRedirectURL(current);

Client & Server Code in One UI Action

 

Mark Correct or Helpful if it helps.


***Mark Correct or Helpful if it helps.***

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I would prefer using client side code in UI action so that user knows which field is mandatory.

you cannot make field mandatory from server side as that has to run on client side.

but what you can do is this

1) check the field value is empty or not in server side

2) if empty then throw error that field is not populated

Something like this

if(current.field == ''){
	gs.addErrorMessage("You should fill the field value for field name");
	current.setAbortAction(true);
	action.setRedirectURL(current);
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader