Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

cancel change

kunal16
Tera Expert

As an OOB configuration, we have a UI action 'Cancel Change' that cancels a change request. This UI action will be visible to all the ITIL users.

I want to restrict the visibility conditions of this UI action such that it should be visible only

1. to requested by users

2. at states New(-5), Assess(-4), Authorize(-3) and Scheduled(-2).

I tried to update the condition but of no use.

gs.hasRole('itil') && (gs.getUserID() == requested_by) && ((current.state == -5) || (current.state == '-4') || (current.state == '-3') || (current.state == '-2')) && new ChangeRequestStateHandler(current).canMoveTo("canceled")

Kindly help.

Thanks in advance!!

1 ACCEPTED SOLUTION

Mihir Mohanta
Kilo Sage

Try below condition



gs.hasRole('itil') && (current.requested_by== gs.getUserID()) && ((current.state == '-5') || (current.state == '-4') || (current.state == '-3') || (current.state == '-2')) && new ChangeRequestStateHandler(current).canMoveTo("canceled")




Thanks,


Mihir


View solution in original post

10 REPLIES 10

Mihir Mohanta
Kilo Sage

Try below condition



gs.hasRole('itil') && (current.requested_by== gs.getUserID()) && ((current.state == '-5') || (current.state == '-4') || (current.state == '-3') || (current.state == '-2')) && new ChangeRequestStateHandler(current).canMoveTo("canceled")




Thanks,


Mihir


Thanks Mihir, it worked.


I need to display cancel change for requested by user in 3 states only and for change manager it should be displayed always. Please suggest

Deepa Srivastav
Kilo Sage

Did you try:-



current.requested_by==gs.getUserID() ; instead of only requested_by..



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.



Thanks,


Deepa


RP2
Giga Contributor

I am updating the OOTB Cancel Change UI action to include mandatory check on 'reason' field & add comment into work_notes upon Canceling Change.  


I am incorporating the on-click functionality.



Condition: gs.hasRole('itil')   &&   new ChangeRequestStateHandler(current).canMoveTo("canceled")



// Client-side 'onclick' function


function cancelchange(){



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



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



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



  g_form.setMandatory('reason', true);



  g_form.showFieldMsg('reason','Reason is mandatory when canceling a Change Request','error');



  return false;   //Abort submission



  }


  else {



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


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


  }



}


if(typeof window == 'undefined') {


  moveToCancel();


}




function moveToCancel(){


  action.setRedirectURL(current);


  if (new ChangeRequestStateHandler(current).moveTo("canceled")) {


  current.update();


  }


}



I left the OOTB moveToCancel unchanged, but it appears that it does not work in conjunction with on-click functionality.   I'm guessing it's trying to execute the moveToCancel on Server Side.   I need all the funcitonality of the ChangeRequestStateHandler(current).moveTo("canceled") which will cancel   current workflows & update open Approval records to no long required.     Can you pls assist with workaround ?