It's all about the answers!

Ask a question

How to change work item type programmatically when attribute value changes?


Daniel Stewart (431520) | asked Feb 10 '15, 12:35 p.m.

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


permanent link
Ralph Schoon (63.1k33645) | 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



permanent link
Ralph Schoon (63.1k33645) | 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
sam detweiler commented Feb 11 '15, 6:47 a.m.

Not 'attribute', complete workitem type..

he wants to change from task to story, or to defect, or a custom workitem type


Ralph Schoon commented Feb 11 '15, 8:21 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Stupid me....


Daniel Stewart commented Feb 13 '15, 10:41 a.m.

I should have been more clear about what I meant. But, yes I'm changing from incident to an issue work item.


permanent link
Ralph Schoon (63.1k33645) | 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
sam detweiler commented Feb 11 '15, 8:35 a.m.

aren't there potential impacts to other attributes in the target workitem type if they are not 100% symmetrical.  


Ralph Schoon commented Feb 11 '15, 9:23 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I haven't tried JavaScript, however, I used the API. I think it should work - as always test this on a test system, obviously.

If the other work item type has new attributes, they will be created. If the editor presentations are different, after reload attributes not in the presentations will not be shown, but they will still be there.
If there is validation or different required attributes then you would have to fix that in the UI.

Your answer


Register or to post your answer.