- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2018 03:19 PM
Hi all,
I created a new change type (minor) using this tutorial, and then used this tutorial to add my own states.
The States I have added for this test is:
- Develop and Implement in UAT
- Test in UAT
What I have found is that when clicking State, the Option is there to choose all available states, instead of seeing just the next state available.
New should show Develop and Implement in UAT only.
I debugged with field watcher, and have found that the client script 'Show valid states values' is not running
In my personal development instance, the client script shows as running when using the field watcher. It is probably worth noting that the change request here was heavily modified by the implementer, however, I cannot see any of their scripts running on the state field with the field watcher so not sure something is cancelling it out, but rather something is wrong with the script includes that I have created for the new change type.
Below are the script inlcudes that I have created for the new change type. Can anyone see why the client script is not running?
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.AUTHORIZE = ChangeRequestStateHandlerSNC.AUTHORIZE;
ChangeRequestStateHandler.SCHEDULED = ChangeRequestStateHandlerSNC.SCHEDULED;
ChangeRequestStateHandler.IMPLEMENT = ChangeRequestStateHandlerSNC.IMPLEMENT;
ChangeRequestStateHandler.REVIEW = ChangeRequestStateHandlerSNC.REVIEW;
ChangeRequestStateHandler.CLOSED = ChangeRequestStateHandlerSNC.CLOSED;
ChangeRequestStateHandler.CANCELED = ChangeRequestStateHandlerSNC.CANCELED;
ChangeRequestStateHandler.DEVELOP_AND_IMPLEMENT_IN_UAT = "develop_and_implement_in_uat";
ChangeRequestStateHandler.TEST_IN_UAT = "test_in_uat";
ChangeRequestStateHandler.prototype = Object.extendsObject(ChangeRequestStateHandlerSNC, {
MINOR:Minor,
initialize: function(changeRequestGr) {
ChangeRequestStateHandlerSNC.prototype.initialize.call(this, changeRequestGr);
this.STATE_NAMES["8"] = ChangeRequestStateHandler.DEVELOP_AND_IMPLEMENT_IN_UAT;
this.STATE_NAMES["12"] = ChangeRequestStateHandler.TEST_IN_UAT;
},
_resetModel: function() {
this._model = null;
var type = this._gr.getValue('type') + "";
if (type == this.NORMAL || type == this.STANDARD || type == this.EMERGENCY)
ChangeRequestStateHandlerSNC.prototype._resetModel.call(this);
else if (type == this.MINOR)
this._model = new ChangeRequestStateModel_minor(this._gr);
},
type: "ChangeRequestStateHandler"
});
ChangeRequestStateModel_minor
var ChangeRequestStateModel_minor = Class.create();
ChangeRequestStateModel_normal.prototype = Object.extendsObject(ChangeRequestStateModelCust_minor, {
draft: {
nextState: [ "develop_and_implement_in_uat" ],
develop_and_implement_in_uat: {
moving: function() {
return this.toDevelopuat_moving();
},
canMove: function() {
return this.toDevelopuat_canMove();
}
},
canceled: {
moving: function() {
return this.toCanceled_moving();
},
canMove: function() {
return this.toCanceled_canMove();
}
}
},
develop_and_implement_in_uat: {
nextState: [ "test_in_uat" ],
test_im_uat: {
moving: function() {
return this.toTestuat_moving();
},
canMove: function() {
return this.toTestuat_canMove();
}
},
canceled: {
moving: function() {
return this.toCanceled_moving();
},
canMove: function() {
return this.toCanceled_canMove();
}
}
},
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 this.toCanceled_moving();
},
canMove: function() {
return this.toCanceled_canMove();
}
}
},
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 this.toCanceled_moving();
},
canMove: function() {
return this.toCanceled_canMove();
}
}
},
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: {},
toDevelopuat_moving: function() {
return true;
},
toDevelopuat_canMove: function() {
return true;
},
toTestuat_moving: function() {
return true;
},
toTestuat_canMove: function() {
return true;
},
type: "ChangeRequestStateModel_minor"
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2018 07:05 PM
Hi Brendan,
I thinks you should be check:
1) The value of new type: "Minor" or "minor"
2) Update "ChangeRequestStateHandler" for new type:
MINOR: "<value of new type>",
=> I thinks you have a typo mistake when updating "ChangeRequestStateHandler"
Hope this help!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2018 03:55 PM
Did you try adding few alert statements to the client script to check, if it is entering the client script?
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2018 04:02 PM
Hey,
No i hadnt. The client script is a default OOB, so not sure if I should be messing with it? Did you know what type of alert statements I could try? This is the client script below.
Show valid states values
function onLoad() {
var validStates = [];
var returnedStates = [];
if (g_scratchpad.validStates)
returnedStates = g_scratchpad.validStates;
var originalValues = {};
originalValues[g_form.getValue('state')] = g_scratchpad.stateModel.stateLabelByValue[g_form.getValue('state')];
validStates.push(originalValues);
for (var i = 0; i < returnedStates.length; i++) {
var keyVal = {};
keyVal[returnedStates[i]] = g_scratchpad.stateModel.stateLabelByValue[returnedStates[i]];
validStates.push(keyVal);
}
g_form.clearOptions('state');
for (var pos = 0; pos < validStates.length; pos++) {
var currState = validStates[pos];
for (var key in currState)
g_form.addOption('state', key, currState[key]);
}
if (g_form.getValue("on_hold") === 'true') {
g_form.showFieldMsg("state", getMessage("Change is currently on hold"));
return;
}
if (g_form.getValue('state') == "-4" || g_form.getValue('state') == "-3" )
g_form.showFieldMsg("state", getMessage("Change is waiting for approval"));
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2018 04:48 PM
Yes you can add alert statements to the OOB scripts. No problem with that. You can revert them later.
Please try below script.
function onLoad() {
var validStates = [];
var returnedStates = [];
alert('inside state value client script');
if (g_scratchpad.validStates)
returnedStates = g_scratchpad.validStates;
alert('returnedStates is '+returnedStates );
var originalValues = {};
originalValues[g_form.getValue('state')] = g_scratchpad.stateModel.stateLabelByValue[g_form.getValue('state')];
validStates.push(originalValues);
for (var i = 0; i < returnedStates.length; i++) {
var keyVal = {};
keyVal[returnedStates[i]] = g_scratchpad.stateModel.stateLabelByValue[returnedStates[i]];
validStates.push(keyVal);
}
alert('validStates are '+validStates.toString());
g_form.clearOptions('state');
for (var pos = 0; pos < validStates.length; pos++) {
var currState = validStates[pos];
for (var key in currState)
g_form.addOption('state', key, currState[key]);
}
if (g_form.getValue("on_hold") === 'true') {
g_form.showFieldMsg("state", getMessage("Change is currently on hold"));
return;
}
if (g_form.getValue('state') == "-4" || g_form.getValue('state') == "-3" )
g_form.showFieldMsg("state", getMessage("Change is waiting for approval"));
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2018 06:08 PM