It's all about the answers!

Ask a question

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


Sunny Kumar (531588) | asked Jan 18 '23, 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:

Code:
dojo.provide("com.example.Project_SetAttrIsanOpportunity");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
    dojo.declare("com.example.Project_SetAttrIsanOpportunity", null, {
 
        getValue: function(attribute, workItem, configuration) {

var WorkItemAttributes = com.ibm.team.workitem.api.common.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('com.stellantis.team.project.IsanOpportunity2');
  
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 (63.5k33646) | answered Jan 19 '23, 3:02 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 My 2 cents

  1. Your script is invalid. A function has to always return a value, be it the original value. See https://rsjazz.wordpress.com/2022/11/25/ewm-attribute-customization-introduction/
  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: https://rsjazz.wordpress.com/2022/11/25/ewm-attribute-customization-introduction/
  3. You could debug scripts. See https://rsjazz.wordpress.com/2022/11/17/debugging-ewm-work-item-attribute-customization-javascript/ how to. If the script does  not show up, it is so faulty that it even does not load.


Comments
Sunny Kumar commented Jan 19 '23, 4:39 a.m. | edited Jan 19 '23, 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 '23, 5:01 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
  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 https://jazz.net/library/article/1093 the last two labs. See links in https://rsjazz.wordpress.com/2022/11/25/ewm-attribute-customization-introduction/ 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. 

Sunny Kumar commented Jan 19 '23, 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 '23, 7:05 a.m. | edited Jan 19 '23, 7:08 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.


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.