How to change work item type programmatically when attribute value changes?
![]() I'm trying to determine the best API or programmatic approach to change the work item type when a radio button value changes. Can anybody give me any pointers on this? Thanks in advance. Dan |
Accepted answer
![]()
Ralph Schoon (61.8k●3●36●43)
| answered Feb 11 '15, 10:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER I tried it out and this script seems to do it (This is an example and not fully tested and I am not liable if the script causes issues etc.). There are various considerations e.g. for which types to work and what to return and why that I leave to the reader. This script only looks at items with a type defect and task and based on the priority it sets a type or returns the current type. Priority is looked for using the display value and not the literal ID. /******************************************************************************* * 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.ValueProvider"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); (function() { var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("com.example.ValueProvider", null, { getValue: function(attribute, workItem, configuration) { var enumerationDisplayValue = workItem.getLabel(WorkItemAttributes.PRIORITY); // var enumerationLiteral = workItem.getValue(WorkItemAttributes.PRIORITY); var currentType = workItem.getValue(attribute); if(currentType=="defect" || currentType=="task"){ if(enumerationDisplayValue=="High"){ return "defect"; } if(enumerationDisplayValue=="Medium"){ return "task"; } } return currentType; } }); })(); Daniel Stewart selected this answer as the correct answer
|
2 other answers
![]()
Ralph Schoon (61.8k●3●36●43)
| answered Feb 11 '15, 2:20 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
As far as I am aware you can not change an attribute type at all. See https://jazz.net/library/article/1002 for best practices. As far as I know the only way to create a new attribute type properly requires modification of the process XML by the admin tools.
Comments Not 'attribute', complete workitem type..
Stupid me....
I should have been more clear about what I meant. But, yes I'm changing from incident to an issue work item. |
![]()
Ralph Schoon (61.8k●3●36●43)
| answered Feb 11 '15, 8:30 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
In general you set the ID of the type in the attribute.
I can think of the following approaches you can try: 1. A JavaScript based attribute customization. See https://jazz.net/library/article/1093 Lab 5 and https://jazz.net/wiki/bin/view/Main/AttributeCustomization. You would return the type ID based on the enumeration literal each time. I would assume the user has to refresh the editor if that happens. 2. A follow up action coded in Java - this is a lot more complex and has to deployed on the server. I would try the 1st approach on a test system I would also - as always - ask myself the question, if this is a good approach. Why do we have this requirement? Is there a better way? Should a human do this change? Comments aren't there potential impacts to other attributes in the target workitem type if they are not 100% symmetrical.
I haven't tried JavaScript, however, I used the API. I think it should work - as always test this on a test system, obviously.
|