How put the creator of a workitem in a custom attribute
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");
|
Accepted answer
Ralph Schoon (63.7k●3●36●48)
| 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
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
Ralph Schoon (63.7k●3●36●48)
| 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 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. |
Ralph Schoon (63.7k●3●36●48)
| 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
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:
|
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");
Comments
Ralph Schoon
commented Jun 29 '16, 10:12 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
From my answer above
|
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.
|
Ralph Schoon (63.7k●3●36●48)
| 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
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: |
Thank you this is ok with the sript down :
dojo.provide("org.example.workitems.providers.Validator");
|
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.