How to show an alert message on the form if user clicked on a button?

Devi12
Giga Guru

Hi,

I have requirement to show an alert message on the form, if user clicks on a button. In "sn_vul_vulnerable_item" form I need to make the "Assigned to" field as mandatory when user clicks on a button "Request exception". I made it using onSubmit client script, but it is working only when user clicked on save or update button. I need to make the "Assigned to" as mandatory if user clicks on "Request exception". How can I do that?

Below are the attachments:

Devi12_0-1680683772874.png

Currently I made Assigned to field as mandatory using dictionary override. This is also not working. 

 

2 ACCEPTED SOLUTIONS

Hi Uday,

Thanks for the reply.

I already have the OOTB UI action named "Request Exception". In that UI action script I have added your script, not working.

Devi12_0-1680707984092.png

 

View solution in original post

Hi @Devi12  write my script after first line then it will work.

View solution in original post

18 REPLIES 18

Anil Lande
Kilo Patron

Check below link for solution:

https://www.servicenow.com/community/developer-forum/how-to-make-fields-mandatory-in-ui-action/m-p/1...

 

https://servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Virendra S
Tera Expert

Please update the UI action (Request exception) script as below.

 

var assignedTo = g_form.getValue(**)  ; // get value of "Assigned to"

if(!assignedTo){ // If assignedto is empty

    g_form.setMandatory(**,true) ; // set assigned to as mandatory

   g_form.save();

}

Hi Virendra,

Thanks for the reply.

I tried the above script in UI action, it is not working

Ankur Bawiskar
Tera Patron
Tera Patron

@Devi12 

please share your UI action script and UI action screenshot

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