It's all about the answers!

Ask a question

Attribute Customization : Script based condition : problem with Incrmenting the counter when work item state changes


yaswanth palem (112) | asked Nov 15 '18, 3:20 a.m.

  Hi,


I have created a custom attribute "Reopen counter", when I change the work item state to "Reopen" the counter will increase. 

Issue: I am facing the issue as if I modify any attribute in the work item when the work item state is "Reopen" then also the "Reopen counter" attribute incrementing.

But the scenario is the "Reopen counter" should increment when the when work item state moved to "Reopen" from any other state.

By using this we can achieve how many times the work item moved to "Reopen" state. with the help of "Reopen counter" attribute.

Script:
dojo.provide("com.ericsson.rlam.ReopenIncrementor");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {
    dojo.declare("com.ericsson.rlam.ReopenIncrementor", null, {
        getValue: function(attribute, workItem, configuration) {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
var status = workItem.getValue(WorkItemAttributes.STATE);
                        var reopenCounter = workItem.getValue("reopen_counter");
if (status === "RLAM_Defect_Management_Workflow.state.s2") {
reopenCounter = ++reopenCounter;
return parseInt(reopenCounter);
}else{
return reopenCounter ;
}
        }
    });
})();

Thank you..

One answer



permanent link
Ralph Schoon (63.6k33646) | answered Nov 15 '18, 7:18 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Nov 15 '18, 8:00 a.m.

 I think I have answered this very same question/context too often now. 


1. https://jazz.net/wiki/bin/view/Main/AttributeCustomization explains how often scripts are called. Calculated values can be called multiple times when a work item is opened and attributes they depend on are changed.

2. There is no real good way in https://jazz.net/wiki/bin/view/Main/AttributeCustomization to detect a state change. In a calculated value you can only detect the current state using the status attribute. The only way to use the API from the link to detect the state has changed is to use a calculated hidden attribute, that contains the last state of the work item when t was saved and compare that value against the current value. If they are different the state change is detected. Not sure how reliable that is and the details to exploit it for your case though.

3. Consider to look into the JRS Report Builder if a report can give you that information. It should not be stored in the work item anyway.
 

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.