It's all about the answers!

Ask a question

Set Filed Against field with an attribute customization


Angelo Corna (26148381) | asked Jan 31, 3:07 a.m.
Hi, 

on our EWM project area we've created different WorkItem types. 
Every WorkItem type needs to be available only for a specific Team Area and the idea is to define different Categories with the same name of the WorkItem type and use the Category Visibility feature.

For this reason we would like to set Filed Against field automatically during the WorkItem creation using the WorkItem type value.

For this reason we've create a Calculated Value attribute customization with the following javascript code
dojo.provide(“sample.assignFiledAgainst”);
dojo.require(“com.ibm.team.workitem.api.common.WorkItemAttributes”);
(function() {
 var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
 dojo.declare(“sample.assignFiledAgainst”, null, {
 getValue: function(attribute, workItem, configuration) {
    var wiType = workItem.getValue(WorkItemAttributes.TYPE).toUpperCase();
    console.log(“CUSTOMCODE wiType: ” + wiType);
    return wiType;
 }
 });
})();

The log returns the correct value (the WorkItem type) but the Filed Against field is not set.
What is wrong? Do we need to pass a different Category identifier?

Thanks in advance.
Bye

2 answers



permanent link
Ralph Schoon (63.2k33646) | answered Jan 31, 3:20 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 The work item type has nothing at all to do with the filed against attribute. The filed against attribute represents the work item category, which associates the work item with the project or team area. It is used to be able to report who is responsible for a work item and uses a user readable tree structure to do so. 


The attribute can be read using WorkItemAttributes.FILED_AGAINST. See  https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Accessing_built_in_attributes_of.
I would suggest to read the value and look at it. It should look like /<level1>/<level2> e.g. /JKE/BRN. 


Comments
Angelo Corna commented Jan 31, 3:22 a.m. | edited Jan 31, 7:10 a.m.
Ralph,

thanks for your response. We need to set filed against attribute. Is it possible with javascript?

Ralph Schoon commented Jan 31, 7:23 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

As Davyd says, if you can configure a calculated value for filed against, you can most likely set it. Use getValue and getName first to get the information and how it looks like. What you get as getValue would be what you can return. I am pretty sure the value is a path like structure.

If you need to set different values for different work item types, you need some kind of mapping like Davyd shows in his answer.


permanent link
Davyd Norris (2.3k217) | answered Jan 31, 5:49 a.m.
You can definitely do this, and you're almost correct, but you can't use the name directly.

Each Category has a name but it also has a unique ID, and it's this ID that you must return. This code snippet shows how to set the Filed Against by looking up the ID based on the name. If for some reason the type doesn't match a Category name, you should just return the current value of the attribute

dojo.provide("com.example.ValueProvider");

dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {
  const WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;

  dojo.declare("com.example.ValueProvider", null, {

    getValue: function(attribute, workItem, configuration) {
      const catList = << the array of objects in the form of {name, id} >>;

        const wiType = workItem.getValue(WorkItemAttributes.TYPE).toUpperCase();
        const categoryId = catList.find((item) => item.name === wiType).id;
        return categoryId ? categoryId : workItem.getValue(attribute);
  });
})();

You will need to populate the array of Categories with objects containing the category name and their unique ID. There are various ways to do this, but I assume you won't have many different Work Item types (and therefore not many Categories) so the simplest way would be to just put in console.log() calls in some code that prints out the value as you change the Filed Against field

console.log(workItem.getValue(WorkItemAttributes.FILED_AGAINST));

Your answer


Register or 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.