Avoid Task State based on the Approval State (Pending, Rejected..,)
Accepted answer
You can use the out of the box trigger to prevent moving to the next state while you have a pending review, approval or verification, however this only works for the first of each type. If you create a second one of the same type then the trigger code is 'greedy' and only checks that there is *some* approved and not *all* approved.
We hit this problem and raised a defect, only to be told that this is by design and the team won't fix it. As a result I have had to create a bunch of custom validation code and a dummy field that I attach the validator to.
The following code will check that *ALL* reviews or approvals are complete and flag an error if not. Create a dummy attribute and attach this to the validator, then turn on the trigger to prevent invalid values from being saved. You will probably have to make the check state based as well.
/*******************************************************************************
* CLM workitem customisation scripts
* Project (c) Copyright Davyd Norris 2019. All Rights Reserved.
*
******************************************************************************/
dojo.provide("au.gov.vic.rpv.allApproved.Validator");
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
(function() {
var Severity= com.ibm.team.workitem.api.common.Severity;
var Status= com.ibm.team.workitem.api.common.Status;
var calcApprovals = function(workItem) {
var cpfApprovals = workItem.getProxy().getValue({path : [ 'approvals' ]});
if (cpfApprovals == null) {
return true;
}
for (var i = 0; i < cpfApprovals.length; i++ ) {
if (cpfApprovals[i].cumulativeState !== "com.ibm.team.workitem.approvalState.approved") {
return false;
}
}
return true;
};
dojo.declare("au.gov.vic.rpv.allApproved.Validator", null, {
validate: function(attribute, workItem, configuration) {
console.log('validate allApproved');
var allApproved = calcApprovals(workItem);
return allApproved ? Status.OK_STATUS : new Status(Severity["ERROR"], 'There are incomplete Reviews or Approvals');
}
});
})();
* CLM workitem customisation scripts
* Project (c) Copyright Davyd Norris 2019. All Rights Reserved.
*
******************************************************************************/
dojo.provide("au.gov.vic.rpv.allApproved.Validator");
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
(function() {
var Severity= com.ibm.team.workitem.api.common.Severity;
var Status= com.ibm.team.workitem.api.common.Status;
var calcApprovals = function(workItem) {
var cpfApprovals = workItem.getProxy().getValue({path : [ 'approvals' ]});
if (cpfApprovals == null) {
return true;
}
for (var i = 0; i < cpfApprovals.length; i++ ) {
if (cpfApprovals[i].cumulativeState !== "com.ibm.team.workitem.approvalState.approved") {
return false;
}
}
return true;
};
dojo.declare("au.gov.vic.rpv.allApproved.Validator", null, {
validate: function(attribute, workItem, configuration) {
console.log('validate allApproved');
var allApproved = calcApprovals(workItem);
return allApproved ? Status.OK_STATUS : new Status(Severity["ERROR"], 'There are incomplete Reviews or Approvals');
}
});
})();
Comments
showing 5 of 13
show 8 more comments
One other answer
I think this is only possible by creating a custom advisor.