Cancel confirm window after clicking cancel button

jesusemelendezm
Mega Guru

Hi SN folks,

 

What can I use to configure a confirm pop up - when clicking cancel button on the change form. If user press cancel - It will ask confirmation, if press OK - cancel change- if cancel It must return to change form without cancelling the record.

 

Thanks for your help.

1 ACCEPTED SOLUTION

attachment seems not be working for me ....



this is the code ...


Note : check the 'client' checkbox and in 'onlick' field , paste this cancelTicket();



function cancelTicket(){


      var answer=confirm("Are you sure you want to cancel this record?");


      if (answer==true)


              {


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


      }


      else


              {


              return false;


      }


}



if(typeof window == 'undefined')


      {


      current.state = 8;


      current.update();


      action.setRedirectURL(current);


      gs.addInfoMessage('The current change request has been cancelled.');


}


View solution in original post

32 REPLIES 32

Yes. The client checkbox is selected and copyTicket(); entered in the onclick box.


I get the alert pop-up with the OK and Cancel buttons. But on clicking either button, the pop-up goes away, but no action is executed.


Hi Norton,



Server side script will not work in client side function because of this reason change is not created even you click on ok button. To perform this we have to write change record creation in script include and call script include from function copyTicket();


I created a script include: uCreateChangeCopy


On adding it in the code as follows, it does not execute.



function copyTicket(){


      var answer=confirm("Are you sure you want to copy this record?");


      if (answer==true)


              {


  javascript:uCreateChangeCopy();


      }


      else


              {


              return false;


      }


}



**********************************************************************


script include:


function uCreateChangeCopy(){


var chgID = current.sys_id.toString();


var newChange = new GlideRecord('change_request');


newChange.initialize();


newChange.requested_by = current.requested_by;


newChange.cmdb_ci = current.cmdb_ci;


newChange.type = current.type;


newChange.assignment_group = current.assignment_group;


newChange.assigned_to = current.assigned_to;


newChange.short_description = current.short_description;


newChange.description = current.description;


newChange.impact = current.impact;


newChange.priority = current.priority;


newChange.change_plan = current.change_plan;


newChange.test_plan = current.test_plan;


newChange.backout_plan = current.backout_plan;


newChange.u_reason_for_change = current.u_reason_for_change;


newChange.u_implementation_effect = current.u_implementation_effect;


newChange.u_verification_plan = current.u_verification_plan;


newChange.insert();




//Copy attachments for this change


if (typeof GlideSysAttachment != 'undefined')


    GlideSysAttachment.copy('change_request', chgID, 'change_request', newChange.sys_id);


else


    Packages.com.glide.ui.SysAttachment.copy('change_request', chgID, 'change_request', newChange.sys_id);






gs.addInfoMessage('Change ticket ' + newChange.number + ' created.');


action.setRedirectURL(newChange);


}


Same outcome if i do not have 'javascript:' specified as well.



function copyTicket(){


      var answer=confirm("Are you sure you want to copy this record?");


      if (answer==true)


              {


  uCreateChangeCopy();


      }


      else


              {


              return false;


      }


}


Hi Nortis,



one another way is there to do this



I have a requirement like If click "ok" I have to create a problem record from incident   and if click "cancel" no changes to form


So, for this I created a field on Incident form u_createproblem which will store input of pop up box and it is invisible on form[made invisible through onload client script] copy paste below code for your ui action and test it.




function submitProblem()


{


  var answer = confirm("Workaround is found or not. \n\nIf workaround is present click on OK to resolve the incident \n\nIf workaround not found click on Cancel to create a problem" );


  g_form.setValue('u_createproblem', answer); //this is the field which I created on form which will store answer of pop up box



  gsftSubmit(null, g_form.getFormElement(), 'create_problem');//here create_problem is action name of ui action


}




if (typeof window == 'undefined')


  serverReopen();




function serverReopen() {


  // Set Incident state to active, update and reload the record



  if (current.u_createproblem)


  {


  //gs.addInfoMessage("YES");


  var d="hello";


  current.incident_state = 6;


  current.state=6;


  current.close_code="Solved (Work Around)";


  current.close_notes="Workaround is found, Resolved Incident"


  current.update();


  //gs.addInfoMessage("Incident is Resolved");



  var prob = new GlideRecord("problem");// Instead of problem you can replace change record creation


  prob.short_description = current.short_description;


  prob.cmdb_ci = current.cmdb_ci;


  prob.priority = current.priority;


  prob.assignment_group = current.assignment_group;


  prob.u_category = current.category;


  prob.u_subcategory = current.subcategory;


  prob.assigned_to = current.assigned_to;



  var sysID = prob.insert();


  current.problem_id = sysID;



  var mySysID = current.update();



  gs.addInfoMessage("Problem " + prob.number + " created");


    var _workNotes = "Problem " + prob.number + " created";


  current.work_notes = _workNotes;


  current.update();


  action.setRedirectURL(prob);


  action.setReturnURL(current);


  }



  if (!current.u_createproblem)


  {


    action.setRedirectURL(current);


        }



  }



let me know if any issues.



mark it answered if its resolve your issue