It's all about the answers!

Ask a question

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

vinitha dsouza (14722133) | asked Jun 05 '19, 10:09 a.m.
edited Jun 05 '19, 10:09 a.m.
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


Accepted answer

permanent link
Davyd Norris (2.4k217) | answered Jun 05 '19, 8:12 p.m.
edited Jun 06 '19, 7:43 p.m.
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.


(function() {

  var Severity=;
  var 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 !== "") {
        return false;
    return true;
  dojo.declare("", 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

Ralph Schoon commented Jun 06 '19, 1:10 a.m.

Nice, thanks for sharing. Unfortunately it uses the undocumented proxy API. 

vinitha dsouza commented Jun 06 '19, 5:55 a.m.

Thanks for sharing. let me check this

Davyd Norris commented Jun 06 '19, 8:43 a.m.

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

Ralph Schoon commented Jun 06 '19, 10:27 a.m.

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!

vinitha dsouza commented Jun 28 '19, 4:50 a.m. | edited Jun 28 '19, 5:00 a.m.
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?

Ralph Schoon commented Jun 28 '19, 5:00 a.m. | edited Jun 28 '19, 5:18 a.m.
  1. Conditions do not prevent saving
  2. Validators only prevent saving  if the severity is error and the pre-condition is configured accordingly.

vinitha dsouza commented Jun 28 '19, 5:43 a.m.
i have added them as part of Precondition - "Required Attributes For Condition"
then it should right?

Ralph Schoon commented Jun 28 '19, 6:16 a.m. | edited Jun 28 '19, 6:17 a.m.

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 .

vinitha dsouza commented Jun 28 '19, 9:21 a.m.
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.

Ralph Schoon commented Jun 28 '19, 10:09 a.m.

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. 

Davyd Norris commented Jun 28 '19, 6:38 p.m.
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.

vinitha dsouza commented Jul 01 '19, 5:10 a.m.
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.

Davyd Norris commented Jul 01 '19, 8:09 p.m.
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
Ralph Schoon (63.2k33646) | answered Jun 05 '19, 12:26 p.m.

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

vinitha dsouza commented Jun 27 '19, 8:43 a.m.
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("", null, {

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

vinitha dsouza commented Jun 28 '19, 4:33 a.m.
Hello Team,
Can you update me on this query please?

Davyd Norris commented Jun 29 '19, 10:30 p.m. | edited Jun 29 '19, 10:31 p.m.

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 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.