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

how to get value of custom attribute of type workitem using javascript

I have scenario where I need to check value of custom attribute of type "workitem" in javascript. when I executed this script(added script based condition) every time I am getting null value . My code is,
var workitemAttribute=workItem.getValue(CustomAttributeID);
console.log("Value of Attribute = " + workitemAttribute); /// Output always shows null (LOG: Value of Attribute=null)

Can anybody help me out showing how to get value of custom attribute of type workitem?

0 votes

Comments

Hi Nilesh, did you set a dependency attribute as well, changing of which the value of the expected attribute will change ? Try removing the whole calculated value script, save the project configuration and recreate it. Also note the "CustomAttributeID" should be within double quotes in the getValue().

HI Indradri Basu, Thanks for the quick response. What is need of setting dependency attribute? I am writing condition based java script.I want to get value of custom attribute which is of type "workitem". In above my code I have used double quotes but still it is giving null value getValue("CustomAttributeID"). Can you help me how to get value of attribute using java script?


Accepted answer

Permanent link
not all attribute types are available via javascript.

see the section under

Only values of the following attribute types can be safely read by and returned from scripts:
Ralph Schoon selected this answer as the correct answer

0 votes


4 other answers

Permanent link
Ahh...problem with my fast reading habbit and  I assumed you are probably writing a script based calculated value.
Check the Attribute Customization page and there are examples as well as descriptions for all script based attribute customization options.



0 votes

Comments

HI Indradri Basu, Thanks for the quick response.
 Sorry but I have gone this page which you have attached. I did not find any satisfactory solution over there. They did not given how to access custom attribute of type "WorkItem". Do you have any idea on this or related link will be helpful


Permanent link
 Hi Nilesh, did you ever get this working?  I am facing the same problem...

0 votes

Comments

Check the Attribute Customization page and there are examples as well as descriptions for all script based attribute customization options.And also read and ideally do Process Enactment Workshop for the Rational solution for Collaborative Lifecycle Management the version for RTC and especially lab 5 in the beginning where the limitations are listed.

If the attribute is an attribute then it can be accessed using
var workitemAttribute=workItem.getValue(CustomAttributeID);
Where CustomAttributeID is a string that contains the ID of the attribute that was given when it was created e.g. "com.ibm.my.custom.string".

Ralph, I am familiar with script based calculations - I have written a lot of them.

I need to get the value of a custom attribute of type Work Item
The following code returns NULL (doc.initiative is a Work Item attribute)
var initiative = workItem.getValue("doc.initiative");

hat looks right, make sure it is the actual attribute ID.

I like to name mine com.workitem.attribute.id.__  whatever.

so I KNOW when I use it what it means. "doc.initiative" doesn't give me that feeling.


Permanent link
Ralph, I am familiar with script based calculations - I have written a lot of them.

I need to get the value of a custom attribute of type Work Item

The following code returns NULL (doc.initiative is a Work Item attribute)

var initiative = workItem.getValue("doc.initiative");

I have looked at the webpage that you have referenced and can't find an example with an attribute type of Work Item.

0 votes

Comments

The reason you can't find an example is that the Work Item type is not fully supported. Probably the exact reason it does not work for you as well.

  • Limited support for Items

Currently there is no dedicated API to work with Items or Enumerations and scripts can only use the id of such attributes. If you need additional information, such as the name that corresponds to an Enumeration literal id, you can pass it to scripts using configuration parameters. See the Configuring additional script parameters section for more information.

It should at least return the UUID and not null, I think. Not that you can do very much with the UUID.


Permanent link
I used the following script - calculated value:
// custom-work-item-calc.js


/*******************************************************************************
 * Licensed Materials - Property of IBM
 * (c) Copyright IBM Corporation 2011. All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:  
 * Use, duplication or disclosure restricted by GSA ADP Schedule 
 * Contract with IBM Corp. 
 *******************************************************************************/
dojo.provide("com.example.Calc_WI");

(function() {
    dojo.declare("com.example.Calc_WI", null, {

        getValue: function(attribute, workItem, configuration) {
        	var value = "-";
        	var label = "-";
        	var exception = "none";
        	try{
        		value = workItem.getValue("custom.workitem");
        		label = workItem.getLabel("custom.workitem");
        	} catch (e) {
				exception = "Exception reading the attribute value: " + e;
			}
				
			return "Item:" + "\nValue: " + value +  "\nLabel: " + label + "\nException: " + exception;	
        }
    });
})();

The value went into the descriptions. The values were null when selecting the work item for the attribute.

The values where correct/contained something, when saving.

0 votes

Comments

Thanks Ralph, pressing Save was the key!

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: May 17 '13, 2:08 a.m.

Question was seen: 7,367 times

Last updated: Nov 11 '15, 7:55 a.m.

Confirmation Cancel Confirm