Access custom attribute in a Calculated attribute script
I would like to automatically assign a user to the Owned By field from a "user" custom attribute upon the work item being a certain state. I implement it as a scripted calculated attribute associated with the Owned By field. I can't figure out why my script does not work. It does not update the Owned By field, and it does not give me any error message in the log or on screen. I tried outputing a test string to the log file and it worked. So I have confirmed that I have the correct set up to run the script upon work item state changes. Would someone be able to tell me what I have done wrong??
My custom attributes are:
Below is the script that I have associated as a Calculated Value with the Owned By field.
Thanks,
Alan
My custom attributes are:
<customAttribute id="buo" name="Business Unit Owner" type="contributor"/> <customAttribute id="tpa" name="Technical Process Analyst" type="contributor"/>
Below is the script that I have associated as a Calculated Value with the Owned By field.
dojo.provide("org.example.workitems.providers.CalculatedOwner");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("org.example.workitems.providers.CalculatedOwner", null, {
getValue: function(attributeId, workItem, configuration) {
if (workItem.getValue(WorkItemAttributes.STATE) == "com.ibm.team.rtc.workflow.adoption.state.s1") return workItem.getValue("buo");
else return workItem.getValue("tpa");
}
});
})();
Thanks,
Alan
2 answers
Hi alan, this post is quite old, however the calculated values are pretty restricted in handling Item Types such as owner. Please have a closer look here: https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Debugging_scripts
For items like users the scripting does not yet work.
For items like users the scripting does not yet work.
To access other custom attributes in your script, you need to add the other attributes in the "dependencies" list when you create your custom variable in the process confguration (in the "Types and attributes" section).
I have made the following script, where "cost_internal" and "cost_external" are the custom variables:
Also, even though I'm returning a long (external + internal) my "total_cost" variable is of type "smallString" becuase of a bug in RTC 3.0.1 that will not display numeric custom variables from scripts apparantly.
Hope this helps someone out there :-).
I have made the following script, where "cost_internal" and "cost_external" are the custom variables:
dojo.provide("com.example.ValueProvider"); (function() { dojo.declare("com.example.ValueProvider", null, { getValue: function(attribute, workItem, configuration) { return workItem.getValue("cost_external") + workItem.getValue("cost_internal"); } }); })();Important: Also, remember to enable the "Enable process attachment scripts" option in "advanced settings" on your CCM server (using the web ui or teamserver.properties).
Also, even though I'm returning a long (external + internal) my "total_cost" variable is of type "smallString" becuase of a bug in RTC 3.0.1 that will not display numeric custom variables from scripts apparantly.
Hope this helps someone out there :-).