It's all about the answers!

Ask a question

Can you validate with a script based validation to only go to a state that is dependent of an attribute?

Cesar Sasaki (511285124) | asked Aug 10 '15, 9:03 a.m.

I'm trying to create a script based validator that do this :

In my workflow I have configured this :
State1 : A
State2 : B 
State3 : C

From A you can go either B or C with an action. But I want to validate that you go only to state B (from A) if you select an attribute to value  "B", and only go to state C (from A) if that attribute is set to "C".

Can this be done with a script based validator? If it is do I have to put the STATUS with the script based validator? or the attribute?


2 answers

permanent link
Nate Decker (37814061) | answered Aug 10 '15, 10:52 a.m.
edited Aug 11 '15, 9:03 a.m.

So to paraphrase and make sure I am understanding you, it sounds like you have 3 states and your configuration allows the user to transition from the first state to either the second or third state. However, you want to control those transitions based on an attribute's value. So if attribute 'X' = 'Y' then State 2 is okay, but state 3 is not. If attribute 'X' = 'Z', then State 3 is okay, but state 2 is not.

You could do this with a custom precondition operation advisor, but I think you are right that this is achievable with a JavaScript Attribute Customization.

Create a "Script Based Validation" validator and check for the attribute value using workItem.getValue("");

To get the work item attributes you'll need dojo.require("");

Inside your function, you'll have something like:

var WorkItemAttributes =;

Check the state using workItem.getValue(WorkItemAttributes.STATE);

Use an If/Else block to return true or false according to the rules in the first paragraph.

Edit: Note that you'll also need to enable the Attribute Validation operation behavior and configure the attribute to use the validation script. My response above is from the perspective of implementing this with a Validator, but I think you could also implement it with a Condition. Either way, you'll need a supporting Operation Behavior precondition. For the Condition, you'll need to enable "Required Attributes for Condition".

Edit 2: I was evidently a bit hasty in making my post and slipped an error in there. I think that's what Donald is referring to in his comment below. I had made reference to, but Don is correct that this is the status that is used in a Validator that's returned when it triggers. If you use a validator, your return statement looks something like:



var Status =;

var Severity =;

var SeverityLevel = Severity["WARNING"];

return new Status(SeverityLevel, "Message");


return Status.OK_STATUS;

Obviously you don't need to assign variables for everything, but it's helpful if you're doing a lot of checking or setting in between the lines posted above.

If you use a Condition rather than a Validator, you should only need to return True or False. The Validator gives you a little bit more control because you can throw an error or throw a warning and then also control what the associated message says.

permanent link
Donald Nong (14.5k414) | answered Aug 10 '15, 11:35 p.m.
You seemed to over-think the situation. Since "State A" is the source state and both "State B" and "State C" are the target states, all you need to validate is as simple as - when "State B", the attribute value is "B", and when "State C", the attribute value is "C" (no need to worry about any transitions).

Be very careful when dealing with the terms "state" and "status", as they can mean the same thing, or completely different ones. For example, WorkItemAttributes.STATE returnes the state/status of a work item; while provide constants such as OK_STATUS and interfaces for other exceptions.

Read the articles about attribute customization carefully and debug your code (make sure the script is executed at the very least).

You can also find some validator scripts posted by other users on this forum, such as this one.

Your answer

Register or to post your answer.