The CreatorCon Call for Content is officially open! Get started here.

How to make a Additional Comments field mandatory using UI policy?

Abdul Ahad
Kilo Contributor

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.

1 ACCEPTED SOLUTION

MrMuhammad
Giga Sage

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

Regards,
Muhammad

View solution in original post

12 REPLIES 12

It is not working. It is submitting the form and then redirecting me to the list view of incident table

Hi ,

Can you share your code?

Did you use correct action name in the code?

Thanks,

Pooja M

Hi,

I think you mentioned that it is working fine.

Are you still looking for solution for this?

Regards
Ankur

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

Hello,

I have got a solution to my problem. Thank you for asking.

Regards:

Abdul Ahad

Hi Ankur,

I have a similar requirement but on a different UI Action.

We have a OOB UI Action named "Create Request" on incident module.

As soon as the button is clicked the state changes to "Cancelled" and redirects to service catalog homepage.

Is there a way to make amendments to change the state only when the request has been submitted successfully?

 

Regards,

Surabhi