Avoid Task State based on the Approval State (Pending, Rejected..,)
Accepted answer
* 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
Nice, thanks for sharing. Unfortunately it uses the undocumented proxy API.
Thanks for sharing. let me check this
Unfortunately Ralph, it's the only option sometimes - this one was a particularly annoying reason as there's an out of the box trigger that only half works and it's not considered a defect
Approval handling leaves a lot to be desired. Especially when there are multiple approvals. Agreed. The attribute customization with JavaScript also leaves a lot to be desired. Thanks for sharing, Davyd!
var cpfApprovals = ["1","2"];
- Conditions do not prevent saving
- Validators only prevent saving if the severity is error and the pre-condition is configured accordingly.
No, this does not even make any sense. If this works at all - and I am still to convince it would - I think you need a validatior and a "Attribute Validation" pre-condition configured. Note that the "State" of the work item will be the target state of the selected action. Also see states in https://jazz.net/wiki/bin/view/Main/AttributeCustomization .
The workitem proxy is undocumented and internal API for all I know.
One other answer
I think this is only possible by creating a custom advisor.
Comments
matches: function(workItem, configuration) {
var allApproved = calcApprovals(workItem);
return allApproved;
}
});
})();
The actual Save check for a Condition is run on the server, and the Proxy class is only available in the Web client, so that's why your code fails