Creating Cancel Change button and making it visible only till some stage

prudhvig
Tera Expert

Hi,

I am trying to create a Cancel Change button which has to be visible only in four states of Change. Those states are New, Assess, Authorize and Schedule. When, state reaches Implement, it should not be shown. And, when any user selects the Cancel button, the work notes should be made mandatory before cancelling.

I can do this by Creating a UI Action for Cancel button. Then, for making visible and mandatory, I could create UI policies. But, how do I create UI Policies for buttons? Cant I achieve the entire thing in one go?

Please suggest. Thanks in advance.

9 REPLIES 9

Should be:



(gs.getUserID() == current.opened_by || gs.getUser().isMemberOf(current.assignment_group) || gs.getUser().isMemberOf('CAB')) && (current.state=='new'||current.state=='assess'||current.state=='authorize'||current.state=='scheduled')


Hi Anurag,



I have done accordingly, but still I am not able to see the Cancel button on change form. My UI Action looks like the one below :



Capture1.PNG



Capture.PNG



What might the problem be ? Thanks ina dvance.


The SN Nerd
Giga Sage
Giga Sage

Assuming your using OOB Instanbul Change, there is an OOB 'Cancel Change' button.



See my zero impact on upgrade solution below:



To change when you are allowed to Cancel a Normal Change, navigate to the Script Include ChangeRequestStateModel_normal.



Make the code change below.


I've just allowed you to move to Cancel from any of those states.


Repeat for Standard and Emergency if required.



var ChangeRequestStateModel_normal = Class.create();


ChangeRequestStateModel_normal.prototype = Object.extendsObject(ChangeRequestStateModelSNC_normal, {


      draft: {


              nextState: [ "assess" ],




              assess: {


                      moving: function() {


                              return this.toAssess_moving();


                      },




                      canMove: function() {


                              return this.toAssess_canMove();


                      }


              },




              canceled: {


                      moving: function() {


                              return true;


                      },




                      canMove: function() {


                              return true;


                      }


              }


      },




      assess: {


              nextState: [ "authorize" ],




              draft: {


                      moving: function() {


                              return this.toDraft_moving();


                      },




                      canMove: function() {


                              return this.toDraft_canMove();


                      }


              },




              authorize: {


                      moving: function() {


                              return this.toAuthorize_moving();


                      },




                      canMove: function() {


                              return this.toAuthorize_canMove();


                      }


              },




              scheduled: {


                      moving: function() {


                              return this.toScheduled_moving();


                      },




                      canMove: function() {


                              return this.toScheduled_canMove();


                      }


              },




              canceled: {


                      moving: function() {


                              return true;


                      },




                      canMove: function() {


                              return true;


                      }


              }


      },




      authorize: {


              nextState: [ "scheduled" ],




              draft: {


                      moving: function() {


                              return this.toDraft_moving();


                      },




                      canMove: function() {


                              return this.toDraft_canMove();


                      }


              },




              scheduled: {


                      moving: function() {


                              return this.toScheduled_moving();


                      },




                      canMove: function() {


                              return this.toScheduled_canMove();


                      }


              },




              canceled: {


                      moving: function() {


                              return true;


                      },




                      canMove: function() {


                              return true;


                      }


              }


      },




      scheduled: {


              nextState: [ "implement" ],




              implement: {


                      moving: function() {


                              return this.toImplement_moving();


                      },


                      canMove: function() {


                              return this.toImplement_canMove();


                      }


              },




              canceled: {


                      moving: function() {


                              return this.toCanceled_moving();


                      },




                      canMove: function() {


                              return this.toCanceled_canMove();


                      }


              }


      },




      implement: {


              nextState: [ "review" ],




              review: {


                      moving: function() {


                              return this.toReview_moving();


                      },




                      canMove: function() {


                              return this.toReview_canMove();


                      }


              },




              canceled: {


                      moving: function() {


                              return true;


                      },




                      canMove: function() {


                              return true;


                      }


              }


      },




      review: {


              nextState: [ "closed" ],




              closed: {


                      moving: function() {


                              return this.toClosed_moving();


                      },




                      canMove: function() {


                              return this.toClosed_canMove();


                      }


              },




              canceled: {


                      moving: function() {


                              return this.toCanceled_moving();


                      },




                      canMove: function() {


                              return this.toCanceled_canMove();


                      }


              }


      },




      closed: {},




      canceled: {},




      type: "ChangeRequestStateModel_normal"


});




ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

anurag92
Kilo Sage

Oh you have actually copied, I gave you a pseudo-code. You might need to change it as per the value of states and CAB Board name. Try this condition:



(gs.getUserID() == current.opened_by || gs.getUser().isMemberOf(current.assignment_group) || gs.getUser().isMemberOf('CAB Approval')) && (current.state=='-5' ||current.state=='-4' ||current.state=='-3' ||current.state=='-2')


anurag92
Kilo Sage

and in script part:


g_form.setMandatory('work_notes',true);


g_form.setValue('state',4);