Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

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.

0 votes


Accepted answer

Permanent link

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

0 votes


One other answer

Permanent link

 Thank you Donald Nong.


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

Thank you
Sayli

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details

Question asked: Mar 09 '17, 6:06 a.m.

Question was seen: 1,842 times

Last updated: Mar 10 '17, 5:31 a.m.

Related questions
Confirmation Cancel Confirm