It's all about the answers!

Ask a question

How put the creator of a workitem in a custom attribute


Laurence Chaptal (1623) | asked Jun 28 '16, 5:23 a.m.

We have a workitem and a custom attribute assignation and we want to put the Creator in this attribute.

The script down dosen't work.

dojo.provide("org.example.workitems.providers.AssignCalcValue");
dojo.require("com.ibm.team.workitem.api.common.connectors.HttpConnectorParameters");
dojo.require("dojo.string");


(function() {
    dojo.declare("org.example.workitems.providers.AssignCalcValue", null, {

        getValueSet: function(attributeId, workItem, configuration) {
               
        console.log("1");
        var WorkItemAttributes=com.ibm.team.workitem.api.common.WorkItemAttributes;
        var creat= workItem.getValue(WorkItemAttributes.OWNER);
        console.log("owner :" + creat);
        console.log("2");
        var result= [];
result.push(creat);
        return result;
}
});
})();

Accepted answer


permanent link
Ralph Schoon (63.7k33648) | answered Aug 12 '16, 3:59 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Aug 12 '16, 4:02 a.m.
To make this actually match the question, see the script below.

This is a minimal calculated value that
  1. Reads the work item state
  2. Reads the work item creator name
  3. Reads the work item creator UUID (needed for attributes of type contributor/user)
  4. Logs some data
  5. Returns the work item state value and the creator information as string

Configure it for the Description attribute and make it dependent on the state attribute to see what is happening.

In other contexts, you can return the creatorName to display the name or return the  creatorUUID, if this is an attribute of type contributor/user


/*******************************************************************************
 * 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.calcstate");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
    dojo.declare("com.example.calcstate", null, {

        getValue: function(attribute, workItem, configuration) {
				
            var creatorUUID = workItem.getValue(WorkItemAttributes.CREATOR);
            var creatorName = workItem.getLabel(WorkItemAttributes.CREATOR);
            var creatorInfo = "Creator is: " + "'" + creatorName + "'" + " UUID " + "'" + creatorUUID + "'";
            console.log(creatorInfo);
            var state = workItem.getValue(WorkItemAttributes.STATE);
            var stateInfo = "Value of state is: " + "'" + state + "'";
            console.log(stateInfo);
            return stateInfo + " " + creatorInfo;
        }
    });
})();
Ralph Schoon selected this answer as the correct answer

7 other answers



permanent link
Ralph Schoon (63.7k33648) | answered Jun 28 '16, 6:01 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You might want to start understanding what types of scripts are available, which one to use and what the limitations of the current JavaScript API are. Read this section really carefully: https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript also consider to look at lab 5. It also talks about the limitations.

In addition, please carefully read How should I ask a question in the Forum if I want to receive useful answers? and consider to provide more information what you want to achieve with this.

The script above is a value set and not a calculated value as the classname suggests. It would return a pick list with one user, if configured correctly. Also if configured correctly you would see some odd string (the UUID) - which is what the contributor object returns. With getLabel(), you would get the user name - as string. Dependent of what the type of the attribute is, this might or might not be working as expected, because of said limitations of the API.

Comments
Laurence Chaptal commented Jun 29 '16, 3:54 a.m. | edited Jun 29 '16, 4:15 a.m.

This script is a value set and the custom attribute assignation is list of collaborator type.

It doesn't return a pick list with one user.


permanent link
Ralph Schoon (63.7k33648) | answered Jun 29 '16, 4:48 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jun 29 '16, 5:26 a.m.
Because it is incorrect as you would have seen if you had looked into the log files.
This script works

dojo.provide("org.example.workitems.providers.AssignCalcValue");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {
     var WorkItemAttributes=com.ibm.team.workitem.api.common.WorkItemAttributes;
    dojo.declare("org.example.workitems.providers.AssignCalcValue", null, {


        getValueSet: function(attributeId, workItem, configuration) {
               
        console.log("1");
        var creat= workItem.getValue(WorkItemAttributes.OWNER);
        console.log("owner :" + creat);
        console.log("2");
        var result= [];
result.push(creat);
        return result;
}
});
})();

and returns the owner after the owner has been set and if dependencies are set.
Note, it picks the Owner not the creator, the creator is in
  • WorkItemAttributes.CREATOR

From https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript again see:

Only values of the following attribute types can be safely read by and returned from scripts:
  • Short String
  • Medium String
  • Large String
  • Integer
  • Long
  • Decimal
  • Boolean
  • Timestamp
  • Limited support for Enumeration.
  • Limited support for Items
Owner is an item. You can return the UUID (not the ID) as a value if you have one, you can not search for them, the Label returns the user name.

permanent link
Laurence Chaptal (1623) | answered Jun 29 '16, 9:38 a.m.

With a calculated value and getLabel of Creator I get the name of the Creator but I can't put it in my customize attribute.

dojo.provide("org.example.workitems.providers.AssignCalc");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

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

dojo.declare("org.example.workitems.providers.AssignCalc", null, {

getValue: function(attribute, workItem, configuration) {
        console.log("1");
        var creat = workItem.getLabel(WorkItemAttributes.CREATOR);
        console.log("createur :" + creat);
return creat;
}
});
})();


Comments
Ralph Schoon commented Jun 29 '16, 10:12 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

From my answer above

Owner (or any contributor) is an item. You can return the UUID (not the ID) as a value if you have one, you can not search for them, the Label returns the user name.

So in my script getValue() does the trick


permanent link
Laurence Chaptal (1623) | answered Jun 29 '16, 11:02 a.m.

I tried with your script with getValueSet and getValue of owner

the script doesn't do the trip the custom attribute is list of contributor type


Comments
Ralph Schoon commented Jun 29 '16, 11:14 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

No, my example does work for an attribute of type contributor but not for ContributorList. I don't think you will get JavaScript to work with that type, I am reasonably sure you can create a Java provider that works.

I am also curious what the real requirement is and what the purpose.


permanent link
Laurence Chaptal (1623) | answered Aug 10 '16, 10:19 a.m.

Sorry but I tried with the script down and Etat is null :

dojo.provide("org.example.workitems.providers.Validator");
 dojo.require("com.ibm.team.workitem.api.common.Severity");
 dojo.require("com.ibm.team.workitem.api.common.Status");

 (function() {

 var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;

     dojo.declare("org.example.workitems.providers.Validator", null, {

         validate: function(attribute, workItem, configuration) {
    var Category= workItem.getValue(WorkItemAttributes.FILED_AGAINST);
    var Status= com.ibm.team.workitem.api.common.Status;
    var Etat= workItem.getValue(WorkItemAttributes.state);
    console.log("HERE IS Etat VALUE" + " " + Etat);
             console.log("HERE IS catégorie VALUE" + " " + Category);


Comments
Ralph Schoon commented Aug 12 '16, 3:25 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Because

  1. hat is a validator  another Java Script type other than the ones above
  2. The script is missing dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
  3. The script is incomplete and no one can tell what else is wrong with it.


permanent link
Ralph Schoon (63.7k33648) | answered Aug 12 '16, 3:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Aug 12 '16, 3:29 a.m.
This is a minimal calculated value that
  1. Reads the work item state
  2. Returns the work item state value

Configure it for the Description attribute and make it dependent on the state attribute to see what is happening.

I have now seen the same incomplete code in many similar questions and I can not see any systematic approach of reading documentation, starting with minimal scripts and incorporating suggestions in the discussion on this and other related questions. This does not make me very optimistic that this is going anywhere.



/*******************************************************************************
 * 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) {
				
			return workItem.getValue(WorkItemAttributes.STATE);
			
        }
    });
})();

Comments
Ralph Schoon commented Aug 12 '16, 3:40 a.m. | edited Aug 12 '16, 3:41 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

A slightly more ambitions version:

/***********
 * 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.calcstate"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() { var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("com.example.calcstate", null, {

    getValue: function(attribute, workItem, configuration) {

        var state = workItem.getValue(WorkItemAttributes.STATE);
        console.log("Value of state is: " + "'" + state + "'"); 
        return "Value of state is: " + "'" + state + "'";
    }
});

})();



permanent link
Laurence Chaptal (1623) | answered Aug 12 '16, 7:53 a.m.

Thank you this is ok with the sript down :

dojo.provide("org.example.workitems.providers.Validator");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

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


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

    var Status = com.ibm.team.workitem.api.common.Status;
    var Severity= com.ibm.team.workitem.api.common.Severity;

    dojo.declare("org.example.workitems.providers.Validator", null, {

    validate: function(attributeId, workItem, configuration) {
    var Category= workItem.getValue(WorkItemAttributes.FILED_AGAINST); 
var Etat= workItem.getValue(WorkItemAttributes.STATE);
console.log("HERE IS Etat VALUE" + " " + Etat);
console.log("HERE IS catégorie VALUE" + " " + Category);
if (Etat === "Enchainement_activites_anomalie.state.s1" && Category !== '_Ii-KkMjyEeWM1dgCThyTQQ'){
        return new Status(Severity["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
console.log("Nouvelle");
}
else
        return Status.OK_STATUS;
    }
});
})();

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.