Attribute Customization : (Calculated Value script) can we get the values from custom attribute of Type String List and return those values into other Custom String List attribute?
Vikas Kumar (13●2)
| asked Mar 16 '21, 3:52 p.m.
edited Mar 17 '21, 3:48 a.m. by Ralph Schoon (63.1k●3●36●46) Hello,
I am trying to get values from a Custom Attribute of type String List (A) and return them into another custom attribute of type String List (B). I have a list of active projects in attribute A which are auto populated using "HTTP Filtered Value Set". I have a list of archived projects in attribute B which are auto populated using "HTTP Filtered Value Set". Going forward few active projects may become archived and I wont be able to query on them. So I thought of creating a calculate value script that gets the values from Attribute A and returns them to attribute B. So that I can query on archived projects. Below is my code.
dojo.provide("com.pasa.workitems.providers.ProjectList");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var doDebug = false;
var scriptname = "ProjectList";
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("com.pasa.workitems.providers.ProjectList", null, {
getValue: function(attributeId, workItem, configuration) {
var projectList = workItem.getValue("com.pasa.team.workitem.attribute.projectlist");
var project = workItem.getValue("com.pasa.team.workitem.attribute.projectlistArchived");
var workItemType = workItem.getLabel(WorkItemAttributes.TYPE);
for(var i=0; i< projectList.length; i++){
project += projectList[i] + " ";
}
try{
if(workItemType == "Task") {
if (projectList != null) {
return project;
}
}
else {
return null;
}
} catch(e){
debug("Error while setting Archeived Projects");
}
function debug(display){
if(doDebug){
console.log(scriptname + " " + display);
}
}
}
});
})();
But it is throwing an exception while creating a workitem. Can someone help me on how to resolve the issue and achieve the solution.
Error running operation 'Creating Work Item'
java.lang.String incompatible with java.util.Collection
java.lang.String incompatible with java.util.Collection
Thanks,
Vikas
|
One answer
Ralph Schoon (63.1k●3●36●46)
| answered Mar 17 '21, 3:56 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER As of https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript string lists are not mentioned in the supported types. See section
Only values of the following attribute types can be safely read by and returned from scripts:
I have experimented with list type attributes and JavaScript and I have been unsuccessful. But I stink in JavaScript and there might be others out there that are better.
Note that I have used the capability to write these providers in Java successfully with list type attributes.
You seem to try to cast a String into a collection and that is the error. Consider using a the Web Browser development tools - the debugger (Chrome works best for me).
Comments
Vikas Kumar
commented Mar 18 '21, 3:37 p.m.
Hello Ralph,
1) Yes, you are right I couldn't find String List in the supported types.
2) When you say, you used capability to write these providers in Java are you referring to plugin?
3) I tried debugging in Chrome but for some reason my breakpoints are not being hit. I will try again.
Thanks for the response.
I had added a link to the part of the attribute customization API documentation in the answer below. The blue stuff is links.
Yes, ultimately a Java extension needs to be deployed as a plugin. Here some examples: https://rsjazz.wordpress.com/2013/06/26/attribute-customization-java-based-value-providers-conditions-and-validators/
WRT debugging, do you use ?debug=true in the URL? I have debugged calculated values most of the time. Not sure if all can be debugged.
Vikas Kumar
commented Mar 22 '21, 3:31 a.m.
Ralph,
Thank you for the help I will look into the links you provided.
Vikas Kumar
commented Mar 22 '21, 3:32 a.m.
Yes I did use ?debug=true while debugging the script.
Vikas Kumar
commented Apr 26 '21, 9:32 a.m.
Ralph,
I have created a Java Extension plugin with the help of links you provided. I have a question, in the examples you are just returning an attribute value but how do I get values from a attribute A and return it to Attribute B?
Thanks.
Ralph Schoon
commented Apr 26 '21, 10:40 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi Vikas,
please check https://rsjazz.wordpress.com/2016/07/15/rtc-process-customization-what-you-can-and-cannot-do/ and please pay attention to the fact, that you can only read data in the scripts themselves. If you want to write, you can use a calculated value script, that returns the value you want.
Ralph Schoon
commented Apr 26 '21, 10:44 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Note, I do not understand your use case description. Since attribute customization only works within one work item, what is the benefit you try to achieve? Do you try to copy the Names for the other project areas in a string list attribute? I am not sure if archived project areas would be removed from the project area list attribute. Up to now, the data of project areas that are archived remains in the DB.
showing 5 of 7
show 2 more comments
|
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.
Comments
I have added an error screenshot but for reason its not showing up here. Below is the exception I am getting while creating a workitem: