Alert message onChange Client Script

javis
Giga Expert

Hi all,

I could use some help with what I'm trying to accomplish. I'm trying to create an alert message when the disposition is set to cancelled. Ideally I would like to have the alert message show onChange but I would like a cancel option on the alert message and then have the values return back to what they were before.

Here is my code so far:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

  if (isLoading || newValue === '') {

  return;

  }

  //Alert message if dispostion changes

  if (oldValue != newValue)

  alert('You changed the disposition to ' + newValue + '. Cancelling this Demand item will cancel all associated tasks as well. Are you sure you want to continue?');

  g_form.setValue('cancelled', oldValue);

}

This is a client script, onChange

Thank you in advance!

5 REPLIES 5

vinothkumar
Tera Guru

Hello James,



You can write return false after your alert statement.


Ujjawal Vishnoi
Mega Sage
Mega Sage

Hi James,



You can use confirm in onsubmit client script to achieve this requirement . Use Code as below



function onSubmit() {  


 


var input = g_form.getValue('<field name>');  


      alert(input);    


if (input == 'Win') {  


    var answer = confirm("Please click Ok to continue your order.");  


      if (answer == false){  


            return false;  


      }  


}  


}



Hope this helps.



Regards


Ujjawal


karthik73
Mega Guru

You can try Confirm instead of Alert.


Ujjawal Vishnoi
Mega Sage
Mega Sage

Also if you want the value as previous value then you can set the field to oldValue. Use script as mentioned below.



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (isLoading || newValue === '') {


  return;


  }



  //Alert message if dispostion changes


  if (oldValue != newValue)


var answer = confirm("You changed the disposition to ' + newValue + '. Cancelling this Demand item will cancel all associated tasks as well. Are you sure you want to continue?");


      if (answer == false){


            return false;


  g_form.setValue('<field name>', oldValue);


      }


}



Regards


Ujjawal