confirm box not working as expected

Wayne Richmond
Tera Guru

Hi there. I've created a simple confirm message via an onChange client script:

Type: onChange

Field name: Business Area

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

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

          return;

    }

if(!g_form.isNewRecord()){

    confirm("Changing the Business Area and Assignment group may mean you can no longer access this record due to security rules");

    g_form.setValue('assignment_group','');

}

}

However, when the user clicks Cancel, the actions continue, namely, the field changes to the new value they've selected and the assignment_group field clears (as per the line in the script). This is not what I'd expect. I would expect the field to return to its original value and for the script to stop and not clear assignment_group. Can any help me achieve the desired result?

Thanks

1 ACCEPTED SOLUTION

Please modify the signature i.e. add one more condition oldValue == newValue



as shown below.....



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


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


          return;


}


View solution in original post

12 REPLIES 12

Harish KM
Kilo Patron
Kilo Patron

g_form.setValue('assignment_group',oldValue);


Regards
Harish

Hi Harish. I'm not sure what this is going to do. I still need the assignment_group to be blank when the user selects a new Business Area and clicks OK to the confirmation box.


try this..




  if (confirm("Changing the Business Area and Assignment group may mean you can no longer access this record due to security rules") == true)


{


    g_form.setValue('assignment_group','');


      return true;   // form submitted


}


  else return false;   // form not submitted


Thanks, this works really well, however, the Business Area (category) field still changes regardless of the user's choice. I've tried to update it (line 12) but the compiler doesn't like my code:



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


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


          return;


  }



if(!g_form.isNewRecord()){


if (confirm("Changing the Business Area and Assignment group may mean you can no longer access this record due to security rules") == true)


{


  g_form.setValue('assignment_group','');


      return true;   // form submitted


}


  g_form.setValue('category',oldValue);


  else return false;   // form not submitted


}


}