It's all about the answers!

Ask a question

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


Nilesh Patil (1734150) | asked May 17 '13, 2:08 a.m.
edited Nov 10 '15, 11:13 a.m. by Ralph Schoon (63.5k33646)
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?

Comments
Indradri Basu commented May 17 '13, 3:10 a.m. | edited May 17 '13, 3:17 a.m.

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().


Nilesh Patil commented May 17 '13, 3:46 a.m.

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
sam detweiler (12.5k6195201) | answered May 17 '13, 7:52 a.m.
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

4 other answers



permanent link
Indradri Basu (1.8k1514) | answered May 17 '13, 4:42 a.m.
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.




Comments
Nilesh Patil commented May 17 '13, 6:00 a.m.

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
Paul Rinaldi (31149) | answered Nov 10 '15, 11:03 a.m.
 Hi Nilesh, did you ever get this working?  I am facing the same problem...

Comments
Ralph Schoon commented Nov 10 '15, 11:16 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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".


Paul Rinaldi commented Nov 10 '15, 6:35 p.m.

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");


sam detweiler commented Nov 10 '15, 6:44 p.m.

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
Paul Rinaldi (31149) | answered Nov 10 '15, 6:31 p.m.
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.

Comments
Donald Nong commented Nov 10 '15, 6:49 p.m.

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.


Ralph Schoon commented Nov 11 '15, 2:19 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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


permanent link
Ralph Schoon (63.5k33646) | answered Nov 11 '15, 4:56 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.


Comments
Paul Rinaldi commented Nov 11 '15, 7:50 a.m. | edited Nov 11 '15, 7:55 a.m.

Thanks Ralph, pressing Save was the key!

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.