State Model and UI actions issues

mbayefdieng
Giga Contributor

Hi everyone,   cameronrichard ctomasi

I am working on the state transition of my Normal Change model, and am facing this issue.

When I modify the script includes ChangeRequestStateHandler and ChangeRequestStateModel_normal, I see all the UI actions visible on the form, and the state field shows all transition states.

2017-02-17_08h47_08.png

these UI actions are visible as form buttons and list button,

What did I do wrong?

Script of ChangeRequestStateHandler:

var ChangeRequestStateHandler = Class.create();

// All references to statehandler constants should be through this class ChangeRequestStateHandler

ChangeRequestStateHandler.DRAFT = ChangeRequestStateHandlerSNC.DRAFT;

ChangeRequestStateHandler.ASSESS = ChangeRequestStateHandlerSNC.ASSESS;

ChangeRequestStateHandler.BUILD = "build";

ChangeRequestStateHandler.SCHEDULED = ChangeRequestStateHandlerSNC.SCHEDULED;

ChangeRequestStateHandler.AUTHORIZE = ChangeRequestStateHandlerSNC.AUTHORIZE;

ChangeRequestStateHandler.IMPLEMENT = ChangeRequestStateHandlerSNC.IMPLEMENT;

ChangeRequestStateHandler.CLOSED = ChangeRequestStateHandlerSNC.CLOSED;

ChangeRequestStateHandler.CANCELED = ChangeRequestStateHandlerSNC.CANCELED;

ChangeRequestStateHandler.prototype = Object.extendsObject(ChangeRequestStateHandlerSNC, {

      initialize: function(changeRequestGr) {

ChangeRequestStateHandlerSNC.prototype.initialize.call(this, changeRequestGr);

              This.STATE_NAMES["-6"] = ChangeRequestStateHandler.BUILD;

      },

      type: "ChangeRequestStateHandler"

  });

Script of ChangeRequestStateModel_normal

/*

STATE_NAMES: {

              "-5": "draft",

              "-4": "assess",

            "-6": "build",

              "-2": "scheduled",

              "-3": "authorize",

              "-1": "implement",

              "0": "review", \\ not a used state

              "3": "closed",

              "4": "canceled",

}

*/

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 this.toCanceled_moving();

                      },

                      canMove: function() {

                              return this.toCanceled_canMove();

                      }

              }

      },

      assess: {

              nextState: [ "build" ],

              draft: {//if technical approver requests more information

                      moving: function() {

                              return this.toDraft_moving();

                      },

                      canMove: function() {

                              return this.toDraft_canMove();

                      }

              },

              build: {

                      moving: function() {

                              return this.toBuild_moving();

                      },

                      canMove: function() {

                              if(this._gr.getValue("u_needs_build")=="Yes") return true;

                              return false;

                      }

              },

              scheduled: {

                      moving: function() {

                              return this.toScheduled_moving();

                      },

                      canMove: function() {

                              if(this._gr.getValue("u_needs_build")=="No") return true;

                              return false;

                      }

              },

              canceled: {

                      moving: function() {

                              return this.toCanceled_moving();

                      },

                      canMove: function() {

                              return this.toCanceled_canMove();

                      }

              }

      },

      build: {

              nextState: [ "scheduled" ],

              scheduled: {

                      moving: function() {

                              return this.toScheduled_moving();

                      },

                      canMove: function() {

                              return this.toScheduled_canMove();

                      }

              },

              canceled: {

                      moving: function() {

                              return this.toCanceled_moving();

                      },

                      canMove: function() {

                              return this.toCanceled_canMove();

                      }

              }

      },

      scheduled: {

              nextState: [ "authorize" ],

              authorize: {

                      moving: function() {

                              return this.toAuthorize_moving();

                      },

                      canMove: function() {

                              return this.toAuthorize_canMove();

                      }

              },

              canceled: {

                      moving: function() {

                              return this.toCanceled_moving();

                      },

                      canMove: function() {

                              return this.toCanceled_canMove();

                      }

              }

      },

      authorize: {

              nextState: [ "implement" ],

              scheduled: {//if on hold

                      moving: function() {

                              return this.toScheduled_moving();

                      },

                      canMove: function() {

                              return this.toScheduled_canMove();

                      }

              },

              implement: {

                      moving: function() {

                              return this.toImplement_moving();

                      },

                      canMove: function() {

                              return this.toImplement_canMove();

                      }

              },

              closed: {//if rejected

                      moving: function() {

                              return this.toClose_moving();

                      },

                      canMove: function() {

                              return this.toClose_canMove();

                      }

              },

              canceled: {

                      moving: function() {

                              return this.toCanceled_moving();

                      },

                      canMove: function() {

                              return this.toCanceled_canMove();

                      }

              }

      },

      implement: {

              nextState: [ "closed" ],

             

              authorize: {//if put on hold

                      moving: function() {

                              return this.toAuthorize_moving();

                      },

                      canMove: function() {

                              return this.toAuthorize_canMove();

                      }

              },

              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: {},

      toBuild_moving: function() {

                                                        return true;

      },

      toBuild_canMove: function() {

                                                        return true;

      },

      type: "ChangeRequestStateModel_normal"

});

1 ACCEPTED SOLUTION

mbayefdieng
Giga Contributor

there is a typo in the code of ChangeRequestStateHandler:



ChangeRequestStateHandlerSNC.prototype.initialize.call(this, changeRequestGr);


              This.STATE_NAMES["-6"] = ChangeRequestStateHandler.BUILD;


      },





because of this capital T in this.


View solution in original post

16 REPLIES 16

Yip....just saw it now too! Sorry it took so long.



If you have any issue adding a new change type, reach out, I'm happy to help!


Hi cameronrichard



As you can see in my process when in ASSESS state, the change can progress to either BUILD or SCHEDULE states. How do I restrict the values in the {state} field based on that condition of the boolean {u_needs_build}'?



      assess: {


              nextState: [ "build", "scheduled" ],


                  ...


Hey Mbaye,



Do you need to restrict the state values in this case? Assess is an approval state which means the state field is read-only.



Isn't your workflow determining which the flow from Assess to the next state?



Thanks,



Cameron


on my form the state field is not read only (not my doing) and shows 2 values (build and scheduled). I want it to say build if the choice list {u_needs_build} is "yes", and to say schedule if {u_needs_build} is set to "no"


Got you...this may require a little more code to solve.



To confirm...you can potentially move to two different states depending on a flag set.



A can move to B or C:


        A ==> B (!flag)


        A ==> C (flag)



...and you only want to show the the relevant state in the choice list?



Currently, the code that shows the next valid states does so without condition checking. That could be amended to check a flag populated in the previous update. Let me have a look at that for you.