It's all about the answers!

Ask a question

Access custom attribute in a Calculated attribute script


Alan Kan (6111310) | asked Aug 31 '11, 5:27 a.m.
edited Apr 02 '13, 4:03 a.m. by Ralph Schoon (63.0k33645)
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:
				        <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



permanent link
Ralph Schoon (63.0k33645) | answered Dec 01 '11, 3:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.

Comments
haizi wu commented Nov 18 '12, 1:39 a.m.

Hi, I have the same situation with alan, but I have tested that the opposite way is possible, I can assigned the build-in attribute  to a custom attribute with both of contributor type, why is this, cannot we get the build-in attribute's value?


permanent link
Morten Madsen (3053148) | answered Nov 23 '12, 5:00 a.m.
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:


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

Comments
Morten Madsen commented Nov 23 '12, 5:02 a.m.

Also remember to update your script under Project -> links when you update your script code. After you do this, a reboot of the server, or a manual change to the process xml might be required, to make the change visible to the server.

Your answer


Register or to post your answer.