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

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

0 votes


Accepted answer

Permanent link

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

0 votes


2 other answers

Permanent link
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?



1 vote

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.

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.


Permanent link
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.

1 vote

Comments

Not 'attribute', complete workitem type..

he wants to change from task to story, or to defect, or a custom 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.

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,926
× 1,699

Question asked: Feb 10 '15, 12:35 p.m.

Question was seen: 4,330 times

Last updated: Feb 13 '15, 10:41 a.m.

Confirmation Cancel Confirm