- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 02:42 AM
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 .
Solved! Go to Solution.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 02:57 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 02:52 AM
Hello Vikas,
I think that is not possible via the server side, however you can try it with Data Policies as described here:
Regards, Ivan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 02:52 AM
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.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 02:57 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader