It's all about the answers!

Ask a question

Calculated Value to set an enum attribute to a certain value based on status change

Gagan Kumar (5332) | asked Jan 18, 1:24 p.m.

 Hi Everyone,

I am trying to set a custom enum attribute to a certain value based on status change in a work-item using the below script. but code is not going in to the function, request someone to provide me suggestions:

(function() {
    dojo.declare("com.example.Project_SetAttrIsanOpportunity", null, {
        getValue: function(attribute, workItem, configuration) {

var WorkItemAttributes =;
            var type = workItem.getLabel(WorkItemAttributes.TYPE);
            var state = workItem.getLabel(WorkItemAttributes.STATE);
  //var Yattr = workItem.getAttributeData('y_n.literal.l1');
//var Nattr = workItem.getAttributeData('y_n.literal.l2');

if (type != null && type == 'Project')
                var IsanOpportunity = workItem.getValue('');
if (state != "Proposed" || state != "Prioritize")
                 return 'y_n.literal.l2';
                if (state == "Proposed" || state == "Prioritize")
                    return 'y_n.literal.l1';

One answer

permanent link
Ralph Schoon (61.5k33643) | answered Jan 19, 3:02 a.m.

 My 2 cents

  1. Your script is invalid. A function has to always return a value, be it the original value. See
  2. As far as I can tell, there is no way to detect the state change in any of the script types other than condition. Only in a condition you have access to the selected workflow action. This would show a potential state change. Again, not available in calculated values. I mention this here:
  3. You could debug scripts. See how to. If the script does  not show up, it is so faulty that it even does not load.

Gagan Kumar commented Jan 19, 4:39 a.m. | edited Jan 19, 5:22 a.m.

 Hi Ralph,

Thanks for the answer, Can you please help in these 2 points:

1. I initially tested the same script in condition, but the result is same.
2. I am returning the value under the if condition, Can you please tell me what part of the code is wrong in returning the enum value?

Thanks in advance

Ralph Schoon commented Jan 19, 5:01 a.m.
  1. This part does not make any sense. There are calculated values, default values, value sets,  conditions and validators, all with completely different interfaces and for different purposes. You need a calculated value, so you implement that interface and not conditions. See the last two labs. See links in for further reading.
  2. You only return a value in the if condition, so what value is returned if the condition does not hold? None. So you fail to match the contract. 

Gagan Kumar commented Jan 19, 6:17 a.m.

Hi Ralph,

Thanks for the suggestions, I will look into those and incorporate the changes. May I know whether it is possible to change the enum value based on workflow state ?
If yes, can you please help me with few references. I am new to this domain, appreciate your help.

Thanks in advance. 

Ralph Schoon commented Jan 19, 7:05 a.m. | edited Jan 19, 7:08 a.m.

I thought I have made it as clear as possible already. I do not think that you can use attribute customization to change the enum value based on workflow state (change), because you can not detect the state change, at least not easily. Short answer: NO. It would be nice if you could automate attribute customization on state changes, feel free to create an enhancement request.

You could use a value set and provide a valid selection or you could create a validator that could complain if the value and the state do not match criteria.

If I had to implement something, I would use a follow up action. Note, the change to the enum would happen after the save.

Your answer

Register or to post your answer.