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

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


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 ?

0 votes


Accepted answer

Permanent link

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

2 votes

Comments

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


2 other answers

Permanent link

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.

1 vote


Permanent link

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.

0 votes

Comments

 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 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
× 7,497

Question asked: Feb 08 '17, 12:24 a.m.

Question was seen: 3,985 times

Last updated: Feb 10 '17, 2:21 a.m.

Confirmation Cancel Confirm