It's all about the answers!

Ask a question

How to retrieve work Item state using (workItem.getValue( WorkItemAttributes.STATE )) ?


Jia jang (42111) | asked Feb 08 '17, 12:24 a.m.
edited Feb 08 '17, 12:28 a.m.

Hello,

I am trying the work item customization in RTC and I want to Retrieve current State of workitem using (workItem.getvalue(WorkItemAttributes.STATE)) and set to other presentation called "Current State Of Task".

i.e.
current State of Task : In process 

I have a script Regarding that :

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

(function() { 
    var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes; 
    dojo.declare("client.valueProvider.New_A", null, { 
        getValue: function(attribute, workItem, configuration) { 
            
            var state = workItem.getValue(WorkItemAttributes.STATE); 
           if (state) {            
                switch (state) { 
                    case 'taskworkflow.state.s2':                //In Progress 
                        return "In Process" ; 
                        break;                 
                    case 'taskworkflow.state.s1':                //New 
                            return "New"; 
                        } 
                        break;                 
                }   
            } 
            return ""; 
        } 
    }); 
}) (); 

But Its not Work for me.
can anyone have any Idea regarding this ?

Accepted answer


permanent link
Lily Wang (4.9k714) | answered Feb 08 '17, 12:51 a.m.

The problem is in your "switch" statement. It should be:

-------------
switch (state) { 
                    case 'taskworkflow.state.s2':                //In Progress 
                        return "In Process" ; 
                        break;                 
                    case 'taskworkflow.state.s1':                //New 
                            return "New"; 
                             break;  
                     }
--------------------------
Please also read article https://jazz.net/library/article/1360 about how to debug value provider javascript.

Jia jang selected this answer as the correct answer

Comments
Dinesh Kumar B commented Feb 08 '17, 3:23 a.m.
JAZZ DEVELOPER

yes the last break is out of place, not nested correctly.. it should be with the appropriate case..

2 other answers



permanent link
Dinesh Kumar B (4.1k413) | answered Feb 08 '17, 3:27 a.m.
JAZZ DEVELOPER

you may want to print out to the console, after you get the state value.. then reuse the returned value for your cases.

there is a special note on value returned by getValue for states mentioned in here :
https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Accessing_an_item_s_Status_attri

If the state id is of the form s### where ### is an integer value, getValue() will return a string representation of the integer value. For example by default the Verified state has the id s4 . Therefore when using getValue() the result will be the string "4" .


hence the console.log of the obtained value can ensure you have the right case statements.


permanent link
Jia jang (42111) | answered Feb 09 '17, 1:16 p.m.
edited Feb 09 '17, 5:11 p.m. by Geoffrey Clemm (30.1k33035)

Lily wang and Dinesh Kumar. I would like to express my gratitude for all that you have done . I am most grateful for your support . Thank you for taking the time to help me , I really do appreciate it.


Comments
Ralph Schoon commented Feb 10 '17, 2:21 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 I would appreciate if you would accept one of the correct answers, so that I don't have to. this helps users in seeing the question was answered correctly and they don't have to try to answer.

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.