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

@Devi12 

So did that alert come?

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

No, I didn't get any alert message while clicking on "request exception" button

Uday_Kumar
Giga Guru

Hi @Devi12  How are you ?

Your requirement can be fulfilled by using UI Actions. First create a UI Action by giving table name and in the script paste the script i am pasting here.

function mandatory() {
	alert("You Clicked the Button");
g_form.setMandatory('assigned_to',true);
}

Uday_Kumar_0-1680701494016.png

What i did was when the user clicks on the button it gives an alert and then it makes the assigned_to field mandatory.

My output:

Initially my assigned to field is not mandatory.

Uday_Kumar_1-1680701620786.png

After clicking the button it gives an alert and then it makes the field mandatory.

Uday_Kumar_2-1680701658397.png

Uday_Kumar_3-1680701674123.png

My assigned to field label is implementer in the screenshot.

 

If my solution helps you please mark my Solution Accepted and Helpful.

Thanks and regards

Uday Kumar Valapudasu

 

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

 

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