It's all about the answers!

Ask a question

Why attribute value is not displayed when status switch from one state to another?


sayli Boralkar (159) | asked Mar 09 '17, 6:06 a.m.
edited Mar 09 '17, 6:22 a.m. by Ralph Schoon (63.6k33646)
Hello guys,

I want to set current date and time after selecting workflow from New---->In Progress and In Progress----->Completed.
For this I made two different attributes of type small string and give dependency of Status attribute and add JavaScript created in Calculated Values. whenever I select "Start Working" status from status field then current date and time is displayed on start date attribute but when I select Complete status from status field then actual end date is set to attribute of end date but Start date is not displayed. 

for more clearance I Paste my JavaScript code below :


 dojo.provide("actualenddatescript");                                               // class name

dojo.require("dojo.date.stamp");  
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date");  


(function() { 
    var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes; 
    dojo.declare("actualenddatescript", null, { 
        getValue: function(attribute, workItem, configuration) { 
var abc;
var currentDate= new Date();
var datum = currentDate.getDate();
var mjesec = currentDate.getMonth() + 1;
var godina = currentDate.getFullYear();
            var hours = currentDate.getHours();
            var minutes = currentDate.getMinutes();
            var seconds = currentDate.getSeconds();
var result = datum+"-"+mjesec+"-"+godina+"  "+hours+":"+minutes+":"+seconds+".";
            var state = workItem.getValue(WorkItemAttributes.STATE);
            var state1=workItem.getValue("work_started");
            var state2 = workItem.getValue("actual_ed");
            
                if (state.toString() == "com.ibm.team.workitem.taskWorkflow.state.s2")   //Id of In Progress state
            {     
if(state1)
{
return state1.toString();
}
else
{
abc = result ;
return abc.toString(); 
}
            }
                if (state.toString() == "com.ibm.team.workitem.taskWorkflow.state.s1")    //Id of New State
            { 
            }  
                if (state.toString() == "com.ibm.team.workitem.taskWorkflow.state.s3")    //Id of Complete State
            {
if(state2)
{
return state2.toString();
}
else
{
abc = result;
return abc.toString();            
}               
            } 
else
{

}    
            
            return ""; 
        } 
    }); 
}) (); 

please correct me if I am wrong in above code.

Accepted answer


permanent link
Donald Nong (14.5k614) | answered Mar 09 '17, 8:42 p.m.

It is not about the code, but rather how you use the code. Apparently you have two attributes, so do you use the same Calculated Value script for both? If so, it makes no sense at all, as you may end up with the same value in both attributes. If you have two scripts with one each, and the one you show is for the End Date, it does not make sense either, as the End Date value ends up depending on Start Date.

Note that the Calculated Value only returns a value, but does not say to where. So you should not have the impression that you can set a value to an attribute in the code. Rather, the attribute will get a value from the Calculated Value provider. It can be quite different.

sayli Boralkar selected this answer as the correct answer

One other answer



permanent link
sayli Boralkar (159) | answered Mar 10 '17, 5:30 a.m.
edited Mar 10 '17, 5:31 a.m.

 Thank you Donald Nong.


Now my task work properly. I made some changes in my code.  

Thank you
Sayli

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.