Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Avoid Task State based on the Approval State (Pending, Rejected..,)

Hello Team,

Usecase: Avoid the Task WI Closure when there is Review or Approval Pending.

i see that we have approval based Workflow Trigger. Can you help us what is available to achieve the above?

OR even using Attribute customisation

Thanks,

0 votes


Accepted answer

Permanent link
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');
    }
  });
})();
vinitha dsouza selected this answer as the correct answer

0 votes

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!

Hi Davyd,
i just changed this to Condition script , though console the expected behaviour.
And i also see the Asterik for the attribute where this is configured.
but Save is allowed. Not sure what is going wrong.

If i comment the getProxy line then Mandatory behaivour works fine.
//var cpfApprovals = workItem.getProxy().getValue({path : [ 'approvals' ]});
var cpfApprovals = ["1","2"];

Any hints?
version: 6.0.6.1



  1. Conditions do not prevent saving
  2. Validators only prevent saving  if the severity is error and the pre-condition is configured accordingly.

i have added them as part of Precondition - "Required Attributes For Condition"
then it should right?

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 .

Hi Ralph,
i am just checking atleast this behaviour works,
what i did:
1. Used above script same.
2. No Dependency added.
3. Just configured Validator to this to Description Field.
4. Add Precondition - Attribute Validation.

I see the Error message but Save is possible.

But if i change this to Script  - Example given by you in different forum.
things works.

Can you check this please, Is it because of Non documented API or any other reason.

The workitem proxy is undocumented and internal API for all I know. 

Otherwise, there is no information in the comment above that would allow to check. 

Unfortunately, The work item proxy is only available in the web client - any server side code that uses it will throw an error, and the actual Save check is done on the server side :-(

I ended up setting up a dummy string attribute that I changed to the error message, and then set up a simple validator that checked whether it was empty or not. If it wasn't I used the value of the field as the error message when the server side executed. The simple validator was able to execute on the server.

Unfortunately i could not get what you said.

How you are able set value of Dummy attribute?
I have tried adding this to Script based value but Script doesn't execute.

Create an internal custom attribute of type string, and then use WorkItem.setValue('<myCustomAttribute>') to set its value if you hit an error condition. You could use a Boolean but making it a string means you can set its value to the error message you want to display.

If there's no error then set the value to '', or whatever the default is.

Then you can set up either an attribute validation or a condition to check that attribute and only save if it hasn't changed from '' (read only for condition), or is empty (attribute validation). This script will be really simple and will execute on both client and server as it doesn't have to use any JavaScript client specific code.

showing 5 of 13 show 8 more comments

One other answer

Permanent link

 I think this is only possible by creating a custom advisor.

0 votes

Comments
Hi Ralph,

i have added the above script as Condition type Script. I get the "*" for the attribute but unfortunately the state transition is also allowed.

i just changed below part to return true or false,
dojo.declare("au.gov.vic.rpv.allApproved.Validator", null, {

matches: function(workItem, configuration) {
var allApproved = calcApprovals(workItem);
return allApproved;
}
});
})();

Hello Team,
Can you update me on this query please?
Thanks

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

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,927

Question asked: Jun 05 '19, 10:09 a.m.

Question was seen: 1,581 times

Last updated: Jul 01 '19, 8:09 p.m.

Confirmation Cancel Confirm