
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2020 02:50 AM
I am new to Service Now. I have been assigned a task in which in the first step I need to create a UI action on an incident table and I have done it. The second step includes setting the additional comments mandatory on clicking the UI action and deliver a field message reading: "Please add additional information".
Kindly help me completing my SNOW task.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2020 05:31 PM
Salam Abdul,
Your Question title and question description is contradicting. UI action and UI policy are two different things. So, I am going by question description and this is your code to make additional comments field mandatory and showing the field msg using UI action
Make sure client checkbox is "checked", action name is "mandatory_comments" & onClick is "reopen()"
//Client-side 'onclick' function
function reopen(){
if(g_form.getValue('comments') == ''){
//Remove any existing field message, set comments mandatory, and show a new field message
g_form.setMandatory('comments', true);
g_form.showFieldMsg('comments','Please add additional Information.','error');
return false; //Abort submission
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'mandatory_comments'); //MUST call the 'Action name' set in this UI Action
}
Please mark this correct & helpful if it answered your question.
Thanks & Regards,
Sharjeel
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2020 05:31 PM
Salam Abdul,
Your Question title and question description is contradicting. UI action and UI policy are two different things. So, I am going by question description and this is your code to make additional comments field mandatory and showing the field msg using UI action
Make sure client checkbox is "checked", action name is "mandatory_comments" & onClick is "reopen()"
//Client-side 'onclick' function
function reopen(){
if(g_form.getValue('comments') == ''){
//Remove any existing field message, set comments mandatory, and show a new field message
g_form.setMandatory('comments', true);
g_form.showFieldMsg('comments','Please add additional Information.','error');
return false; //Abort submission
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'mandatory_comments'); //MUST call the 'Action name' set in this UI Action
}
Please mark this correct & helpful if it answered your question.
Thanks & Regards,
Sharjeel
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 12:50 AM
Thank you so much. It worked successfully.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 05:02 AM
Glad to be of help 🙂
Thanks & Regards,
Sharjeel
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2020 08:48 PM
Hi,
You can do this with onSubmit client script please refer below code.
function onSubmit() {
//Get the action value for the button clicked
var action = g_form.getActionName();
if(action == 'cancel') //put the action name from your UI action
{
//Make 'comments' mandatory
g_form.setMandatory('comments',true);
g_form.addErrorMessage('Please add additional information');
return false;
}
}
For more information you can refer the below link.
https://www.servicenowguru.com/scripting/client-scripts-scripting/identifying-ui-action-clicked-subm...
Thanks,
Pooja M