Confirm Box using client script

ashaki
Kilo Expert

I have a requirement to compare change planned start and actual start. if actual start is before planned start, give user an option to select YES to continue or CANCEL to stop and not save. I create an on change client script but change does not continue when YES is selected. Can anyone help edit my script error.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate){
if(newValue == "")
return;

var startDate = g_form.getValue("start_date");
var workDate = g_form.getValue("work_start");
var format = g_user_date_time_format;

if (startDate === "" || workDate === "")
return;

var startDateMs = getDateFromFormat(startDate, format);
var workDateMs = getDateFromFormat(workDate, format);

if (startDateMs > workDateMs) {
var answer = confirm("Change request cannot be implemented before planned start time begins");
if (!answer){
return false;

 

1 ACCEPTED SOLUTION

ScienceSoft
Tera Guru

In your case need to use 2 onChange client scripts so I’m not sure that is a good idea. But an onSubmit() client script can cancel form submission by returning a value of false. I attached the pictures below

 

find_real_file.png

Another way is to use the AJAX call. And I found a good solution on the following link:

https://community.servicenow.com/community?id=community_question&sys_id=fdc143a9db98dbc01dcaf3231f96...

View solution in original post

4 REPLIES 4

tchan
Tera Contributor

Shouldn't you use onSubmit instead of onChange?

ScienceSoft
Tera Guru

In your case need to use 2 onChange client scripts so I’m not sure that is a good idea. But an onSubmit() client script can cancel form submission by returning a value of false. I attached the pictures below

 

find_real_file.png

Another way is to use the AJAX call. And I found a good solution on the following link:

https://community.servicenow.com/community?id=community_question&sys_id=fdc143a9db98dbc01dcaf3231f96...

ashaki
Kilo Expert

Thank you!

This has helpful and an working as expected

pavana1
Tera Contributor

where we have to see the confirm method in servicenow  

i need to remove instance name in that popup box