Alert() method not working

amruta04
Kilo Contributor

Hello,

I want to add an alert when the user selects a saturday or sunday from the datepicker.

But my simple alert('my msg') is not working in the catalog client script.

Could you please assist.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Amruta,

Even the first line of alert is not working on form load?

Can you check whether this script is active.

For your requirement here is the full script

var date = g_form.getValue('<yourDateVariable>');
var dObj = new Date(date);
var selected_day = dObj.getDay();

if(selected_day == 6 || selected_day == 7){

alert('Date selected is Saturday or Sunday');

}

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

4 REPLIES 4

Domenic Horner
Tera Expert

Hi, are you able to post your client script?
You can try using g_form.addInfoMessage('message'); rather than your `alert`

Have you changed the "Run on" field on your client script to "Service Portal" or "All"?

Shweta KHAJAPUR
Tera Guru

Hi,

It will run. Check have you put alert in any condition. If you are running it on portal the select UI type to ALL. Instead of that you can also use g_form.addInfoMessage('my msg');

Hi Ankur,

Thanks for your reply. Its working fine

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Amruta,

Even the first line of alert is not working on form load?

Can you check whether this script is active.

For your requirement here is the full script

var date = g_form.getValue('<yourDateVariable>');
var dObj = new Date(date);
var selected_day = dObj.getDay();

if(selected_day == 6 || selected_day == 7){

alert('Date selected is Saturday or Sunday');

}

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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