The CreatorCon Call for Content is officially open! Get started here.

Multiple popups

sbolton
Mega Expert

I have an onChange client script that runs when an incident is resolved the client script will pop up a dialog box for the user.   When I resolve the incident from selecting the resolved state and   save the incident I only receive one popup from my CS.   But when i resolve the incident from my UI action (resolve incident) I receive 2 back to back popups. If i comment line 15 out I do not receive the popup BUT the incident does not save after the CS popup closes can someone help me out on why I might be seeing two popups when using the UI Action?

If i comment line 15 out I do receive the popup BUT the incident does not save after the CS popup closes can someone help me out on why I might be seeing two popups when using the UI Action?

function resolveIncident(){

//Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields

  g_form.setValue('incident_state', 6);

  g_form.setValue('state', 6);

    if (g_form.getValue('comments') == '') {

      //Remove any existing field message, set comments mandatory, and show a new field message

  try {g_form.hideFieldMsg('comments');} catch(e) {}

 

      g_form.setMandatory('comments', true);

      g_form.showFieldMsg('comments','Comments are required when resolving an Incident','error');

        return false; //Abort submission

      }

          //Call the UI Action and skip the 'onclick' function

          gsftSubmit(null, g_form.getFormElement(), 'resolve_incident'); //MUST call the 'Action name' set in this UI Action

 

}

//Code that runs without 'onclick'

//Ensure call to server-side function with no browser errors

if (typeof window == 'undefined')

serverResolve();

function serverResolve(){

    current.incident_state = 6;

    current.update();

    }

1 ACCEPTED SOLUTION

bernyalvarado
Mega Sage

Hi Sean, I'm appears to me that you're getting two alerts because you're setting both incident_state and state. You may have some code in your instance which is keeping these in sync and so then your onChange (which i assumed is for either state or incident_state) is then getting executed twice. Try setting only one, but not the two



You can start by trying to set only the state one. Meaning, comment out line 03 of your UI action. If that doesn't work then you can try keeping line 03 and commenting out line 04.



Please keep me posted how it goes, i'm really curious if this is the answer to your mystery



Thanks,


Berny


View solution in original post

7 REPLIES 7

coryseering
ServiceNow Employee
ServiceNow Employee

Hi Sean,



Can you show us the onChange script code as well?


Sure



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


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


  return;


  }


  //Type appropriate comment here, and begin script below


  var reassignment = g_form.getValue('u_inc_reassignment_count');


  var tier = g_form.getValue('incident.assignment_group.u_tier_one_support_group');


  var open = g_form.getDisplayBox('opened_by').value;


  var assigned = g_form.getDisplayBox('assigned_to').value;


  var fTime = g_form.getValue('u_first_tier_resolved');


  var isItil = g_user.hasRole('itil');


  var isItiladm = g_user.hasRole('itil_admin');


  var isAdm = g_user.hasRole('admin');


  var type=g_form.getValue('contact_type');






if (newValue == 6 && newValue != oldValue && reassignment == 0 && tier == 'true' && (isItil || isItiladm || isAdm)&& (open == assigned || type=='self-service') && fTime == 'false' ){



  var answer = confirm('Select OK for First Contact Resolution or select Cancel if this is not a First Contact Resolution.');


  if (answer == true){



  if (answer == true){


  g_form.setValue('u_first_tier_resolved','true');


  g_form.setMandatory('comments', true);


  g_form.save();


  }


  else g_form.setValue('u_first_tier_resolved','false');


  g_form.save();


  }


}


}


coryseering
ServiceNow Employee
ServiceNow Employee

Hi Sean,



I think there is some code-duplication going on there. You check the answer twice- once inside an if condition that only runs if answer is already true. Additionally, in the case where user confirms that they want to continue, you save the form twice.



In a simplified version of this code- where I set a form value in my UI Action that would trigger an onChange script if set manually, I can sporadically reproduce, but only when I save the form record inside the onChange *and* when using the UI Action. There seems to be an inconsistancy here, which is odd and annoying.



Do you really want to save the form in the onChange script? And do you want to save it regardless of the user's response to the confirmation dialog?



I would simplify the onChange to remove the double-answer-check and remove both of the g_form.save() calls. See if you can still reproduce the issue, or if the behavior is more inline with your expectations.


line is 22 is a mistake - this must have been a c+p error.   The g_form.save() was when i click cancel from the dialog box it does not save (threw that in there right before my post). I would like the CS to pop up and the user to select OK / Cancel (process) and then the UI action to process if all the mandatory fields are filled out.   I know the CS wont save unless all the mandatory fields are filled out but that is OK



I am still stumped on why the UI action throws up 2x dialog boxes.