Pop up to confirm cancellation

shristy2
Giga Expert

Hi All,

I have the requirement that : On the incident form their is incident status code as cancelled.

find_real_file.png

When the user clicks on that i want a pop up saying : " Do you want to cancel this incident " and two buttons should be their i.e., Yes or no.

If user clicks yes the ticket should get cancelled and if he clicks no then it should remain in the same page.

Kindly provide your input.

Regards,

Shristy

1 ACCEPTED SOLUTION

raveena2
Kilo Expert

Hi shrishty,


Try this code


function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}




var value = g_form.getValue('incident_state');// field name
if(value==12) // field value
  {
  if(confirm("Do you want to cancel"))
{
g_form.save();
}
    else
    {
    g_form.setValue('incident_state',oldValue);
    }


  }
}



Regards,


Raveena Bhatia



PS:Mark this answer as correct or useful or hit like


View solution in original post

14 REPLIES 14

Hi Gurpreet/Mihir/Srinivas/Raveena,



As i have have created the onchange script with the help of you and mihir,kindly help me with glide dialogue window please.


I am new to servicenow and dont have much idea about it.


I went to link but couldnot find out what to be done.



Kindly help.



Regards,


Shristy


Hi,



try this, change the field name as per your requirement.



function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
          return;
    }


    //Type appropriate comment here, and begin script below

var value = g_form.getValue('incident_state');// field name
alert("value" +value);
if(value==6) // field value
  {
    alert("inside if");
    if(!confirm("do you want to cancel"))
      g_form.setValue('incident_state',oldValue);// it will return to previous value if cancelled.
  }
   
}


Regards
Harish

akshaybhardwaj
Mega Guru

Hi Shristy,



This code can help you,change according to your requirement.



function submitConfirm() {


    if (confirm('Are you sure you want to submit a priority one incident?')) {


  g_form.setValue('priority', '1');


    if (g_form.isNewRecord()) {


  g_form.save();


    } else {


  g_form.submit();


    }


    }


}


raveena2
Kilo Expert

Hi shrishty,


Try this code


function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}




var value = g_form.getValue('incident_state');// field name
if(value==12) // field value
  {
  if(confirm("Do you want to cancel"))
{
g_form.save();
}
    else
    {
    g_form.setValue('incident_state',oldValue);
    }


  }
}



Regards,


Raveena Bhatia



PS:Mark this answer as correct or useful or hit like


shristy2
Giga Expert

Hi Raveena/Akshay/Gurpreet/Mihir/Srinivas,





Thank you for your valuable time spent on this query.


My issue is resolved with the help of you all.




Regards,


Shristy Agrawal