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

Set a tag using Calculated Values script

I'm trying to set a default/dynamic tag based on work-item type using Calculated Values script

I tried this code:

// IWorkItem workItem = workingCopy.getWorkItem();

List<string style="box-sizing: border-box;"> tags = workItem.getTags2();
tags.add("NewTag");
workItem.setTags2(tags);</string>
<string style="box-sizing: border-box; font-size: 13px;">
<string style="box-sizing: border-box; font-size: 13px;"> This is the error: </string>
<string style="box-sizing: border-box; font-size: 13px;">
</string>
com.ibm.team.repository.common.TeamRepositoryException: Unexpected exception type at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.handleException(ScriptAttributeValueProvider.java:281) at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.getValue(ScriptAttributeValueProvider.java:69) at com.ibm.team.workitem.common.internal.attributeValueProviders.AttributeValueProviderRegistry$SafeValueProvider.getValue(AttributeValueProviderRegistry.java:44) at com.ibm.team.workitem.common.internal.model.impl.AttributeImpl.getValue(AttributeImpl.java:899) at sun.reflect.GeneratedMethodAccessor147.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56) at java.lang.reflect.Method.invoke(Method.java:620) at com.ibm.team.repository.common.internal.util.ItemStore$ItemInvocationHandler.invoke(ItemStore.java:597) at com.sun.proxy.$Proxy47.getValue(Unknown Source) at com.ibm.team.workitem.client.internal.DependencyHandler$Worker.runProtected(DependencyHandler.java:51) at com.ibm.team.foundation.client.util.FoundationJob.run(FoundationJob.java:68) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53) Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot find function setTags2 in object [object com.ibm.team.workitem.common.internal.scripting.WorkItemAPIType]. (settagsaos.js#17)
</string>
<string style="box-sizing: border-box; font-size: 13px;">
</string>
<string style="box-sizing: border-box; font-size: 13px;"> What did I do wrong? how can I create a tag using dojo script base code? </string>
<string style="box-sizing: border-box; font-size: 13px;">
</string>
<string style="box-sizing: border-box; font-size: 13px;">Gil</string>

0 votes


Accepted answer

Permanent link

For all I can tell you can not set a tag using JavaScript attribute customization.
You would need to use a Java based attribute customization or a server side extension.
Note that default values are pretty much useless for your purpose, because the default value for a specific type is useless as you can change the type later and the default will not.

Gil Br selected this answer as the correct answer

0 votes


One other answer

Permanent link

The code you refer to is code for the Plain Java Client Libraries and not for the JavaScript API. This is the information for attribute customization: https://jazz.net/wiki/bin/view/Main/AttributeCustomization you basically have setValue() and that is it.

I have not tried, but the tag attributes expect a list of strings.

0 votes

Comments
Hi Ralph,

Thanks for the prompt answer!

Tags is of type List

This still fails:

getValue: function(attribute, workItem, configuration) {
// return ["SAOS"]; //fails with: Error running operation 'Creating Work Item'
java.lang.String incompatible with java.util.Collection
//Trying:
workItem.setValue(attribute, ["SAOS"]); 

This is the error:
TypeError: Cannot find function setValue in object [object 
com.ibm.team.workitem.common.internal.scripting.WorkItemAPIType]. 

Trying to add:
setValue: function(attribute, workItem, configuration) {
//Also fails to run

Please advise
Gil

Sorry, I can't. Not sure how that should work. For API examples read https://jazz.net/wiki/bin/view/Main/AttributeCustomization
For some additional examples read

  Last lab.

You could try to set a string as value and use a comma e.g. "tag1,tag2" or "tag1 tag2".

That is all I can do. I have no time to experiment.

I have the SDK API working version, there it uses:

List<String> tags = workItem.getTags2(); 
tags.add("MyNewTag");
WorkItemWorkingCopy wcsrc = wcm.getWorkingCopy((IWorkItemHandle) workItem.getItemHandle());
wcsrc.getWorkItem().setTags2(tags);

I need the Dojo script Calculated Values script based version for returning or converting a string to a collection (the type of Tags).
Is there any other way to set a default tag per work-item type? 
I like to identify a work-item that has been moved from one Project Area to another.

Any thoughts ideas are welcome
Gil

I doubt you can even detect a work item is moved (versus just created) in the JavaScript Attribute customization.
It might be possible to detect that in a follow up action.

My thought was to set a tag to the work-item before the move and detect it by the tag after the move. The work-item is created in the original Project Area as a child work-item and with a unique type so I wanted every such work item type to have a mark, tag in this case. Is there a way to set a default tag to a specific work-item type (e.g. task) either from script or from Default Values?


Gil

showing 5 of 6 show 1 more comments

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
× 10,937
× 24

Question asked: Jul 24 '18, 9:06 a.m.

Question was seen: 2,343 times

Last updated: Jul 25 '18, 11:31 a.m.

Confirmation Cancel Confirm