It's all about the answers!

Ask a question

How to add a default Text in a customized field


PRASANTA CHAUDHURI (11031625) | asked Dec 22 '14, 2:20 p.m.
How to add a default Text in a customized field followed by Task ID , everytime while creating a work item.
Example -- After submitting new task , on save the customized field will show text like "PRNT-Task000231".
where PRTN- is the default Text , Task is the Type of the workitem getting created and  000231 is the ID of the workitem being created .

Request your help and details on how to do it.

Thanks & Regards

PKC

Accepted answer


permanent link
Brian Fleming (1.6k11928) | answered Dec 22 '14, 2:55 p.m.
Create a Script Based Calculated Value and associate it with your custom attribute.  A sample script is below.  Note that workItem.getValue(WorkItemAttributes.TYPE) returns the id of the workitem type so you will need to map these to the workitem type name within your script as I have done for defect and task. 

/*******************************************************************************
* 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.test");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
    dojo.declare("com.test", null, {

        getValue: function(attribute, workItem, configuration) {

var type = workItem.getValue(WorkItemAttributes.TYPE);
if (type == "defect") {
  type = "Defect";
} else if (type =="task") {
  type = "Task";
}
var id = workItem.getValue(WorkItemAttributes.ID);
var state = workItem.getValue(WorkItemAttributes.STATE);
if (!state) return ""; //returns an empty string prior to workitem being saved
return "PRNT: "  + type + id;

        }
    });
})();
PRASANTA CHAUDHURI selected this answer as the correct answer

Comments
PRASANTA CHAUDHURI commented Dec 23 '14, 3:37 a.m.

Thanks Brian

This has worked very nicely.

If you have some more scripts , Request your posting or let me know the URL

Regards

PKC

Prasanta Kumar Chaudhuri

Your answer


Register or to post your answer.