how to get value of custom attribute of type workitem using javascript
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?
Accepted answer
4 other answers
Check the Attribute Customization page and there are examples as well as descriptions for all script based attribute customization options.
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.
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.
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.
// 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
Indradri Basu
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
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?