Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

AttributeCustomization: Custom value

 Hi, 

I created two custom attributes: test_string and test_string01, both smallString type.. 
When I type some value in test_string, I would like to use that value in test_string01 to be automatically entered.

I used Script Based Calculated Value and created "test_str", which use this script:

dojo.provide("org.example.workitems.providers.CalculatedValueString");

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

dojo.declare("org.example.CalculatedValueString", null, { 

getValue: function(attribute, workItem, configuration) { 

var test_stringAttribute = workItem.getValue("com.ibm.team.workitem.attribute.test_string"); // Note: This is the attribute ID and not the name 
var test_string = test_stringAttribute; 

return test_string; 

}); 
})(); 

and on test_string01 attribute, I chose calculated value "test_str", and on Dependencies, I added test_string.

But this doesn't work.

Am I doing something wrong?

Please help,

Regards,

0 votes



8 answers

Permanent link
Milan,

have you looked into https://jazz.net/library/article/1093 Lab 5?

You need to enable scripting too, before it will work, see the workshop above. Another thing is that you should set your calculated value attribute to read only (not required). Otherwise, without looking at the logs, I would assume your script to work.

0 votes

Comments

And you probably want to add a

dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
underneath your dojo.declare, although that should not be strictly required.


Permanent link
 Hi Ralph, 

thanks for your answer. 
I've already enabled javascript customization before doing anything with javascript. 
I customized some things already, but I can't make to work my string task asked before.
So, I have a couple of questions:
- Where can I find which dojo class is required for some part? For example, I need to get value from one custom attribute string, and use it as default in other custom attribute string...
- I have a situation where I must multiply two entered integers in work item, and get result with JavaScript. I did it successfully, and when I want to compare that result with some value, I must return some string in other custom attribute of type smallString.

I used TotalCostScriptedCalculatedValue class for getting multiply value: 

dojo.provide("com.apisit.providers.script.TotalCostScriptedCalculatedValue");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");


(function() {
    dojo.declare("com.apisit.providers.script.TotalCostScriptedCalculatedValue", null, {

        getValue: function(attribute, workItem, configuration) {
    console.log("- Start");
   
    var broj1 = workItem.getValue("com.apisit.workitem.broj1");

    var broj2 =workItem.getValue("com.apisit.workitem.broj2");

    var rez = broj1*broj2;

    return rez;

        }
    });
})();

When I tried to use the same class in another JavaScript file for getting string value based on given result before:


dojo.provide("com.apisit.providers.script.TotalCostScriptedCalculatedValue");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");


(function() {
    dojo.declare("com.apisit.providers.script.TotalCostScriptedCalculatedValue", null, {

        getValue: function(attribute, workItem, configuration) {
   
    var rez = workItem.getValue("com.apisit.workitem.rez");
   

   
    if(rez > 10)
    return "Veci od 10";
    else    
    return "Manji od 10";
   
   
        }
    });
})();

I got the result of multiplying numbers in my string field again, but in string format (like a decimal).
So, that means that I can't use two same classes on differnet javascript files loaded for same project area?

Which class should I use instead of this?

And one more question: 

I have some enumeration attribute which I would like to fill from script. 
Can I get enumeration values (together with its literal id's) from javascript file (just return some array)?

Regards,

0 votes


Permanent link
Milan,

have you looked into https://jazz.net/library/article/1093 Lab 5? I ask this again, because several of your questions are answered there.

I typically use
var estimate=parseInt(workItem.getValue(WorkItemAttributes.ESTIMATE));
To convert from the string representation to something that is an integer. All examples in https://jazz.net/library/article/1093 that do calculations do that. You can use whatever JavaScript provides to do that. I am not a Dojo expert, but there are also DoJo methods to do these conversions that I have seen used in this forum.

You can fill enumerations from scripts. You have to pass back the enumeration literal ID.

I don't think you can get the value of an attribute and use that to compute a default value. Default values are created during creation of the work item. Only very few attributes have a value already at that point in time. So I am not sure this is possible. Probably depends on the input attributes and what you want to do.

0 votes


Permanent link
 Hi Ralph,

I looked at the labs, but what I need according to integer is next:
For example, I want to multiply two numbers, and with JavaScript get result in other custom attribute.
After that, I would like to compare result is it bigger than 10 or not for example.
So, based on multiply result, I must show some string expression, for example:
if(rez > 10){
return "Bigger than 10";
}
else
{
return "Not Bigger than 10";
}

So, the custom attribute where I want to show this string expression is type smallString, but instead of string expression, I got previous multiply result in smallString, even I sad return "Bigger than 10".
Hope you understand me.

Regards,


0 votes


Permanent link
Milan,

All I have used so far in this area is described in 5.2.1 Total Cost Calculated Value. It uses parseInt() as described above to get a number from the string. https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript shows a bit more information on types supported. As far as I can tell you need to convert the values to something useful, probably because JavaScript is unfortunately untyped.

0 votes


Permanent link
 Hi Ralph,

my example with two strings what I asked at the start works, I don't know, but there is some weird behaviour when using scripts. 
Sometimes it looks like that example doesn't work properly, but after some time, without doing any changes, it works.
Well, I used this for getting value of one string and putting in another:

dojo.provide("com.apisit.providers.script.TotalCostScriptedCalculatedValue");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");


(function() { 

dojo.declare("com.apisit.providers.script.TotalCostScriptedCalculatedValue", null, {
getValue: function(attribute, workItem, configuration) { 

var test_stringAttribute = workItem.getValue("com.apisit.team.workitem.test_string"); 


return test_stringAttribute; 

}); 
})(); 

0 votes

Comments

Milan, so far I was able to proof that in most of the cases, where I ran into problems, I was doing something wrong. There are some defects against Scripting however and we ran into something funny recently where we had different behavior on the Eclipse Client versus the Web UI.

Having said that, I have not seen things fixing themselves. One thing to note is, if you test scripting, close the work item and reopen it after changing the script, otherwise the script is cached and won't reload.

I honestly don't understand what you are asking above. The script also basically passes the input value back into the attribute and does noting with it. So I think I am stuck.

 Hi Ralph,


I got it, I know that I must reload script and reopen work item if any change is happened in js file. 
I figured out some thing watching the pdf and site which you gave me.
Thanks for that.
I 've also tried to fill out enumeration list with values from a script, I succeeded, but there is a warning that enumeriation can not be filled with value provider because the literal id's won't be generated.
just one more question:
I know that I can set default value for enumeration on enumeration attribute in PA configuration.
Is there possible to set defaulte value through the javascript?
Example: I have an enumeration list from 1 to 12 (typical numbers), and based on the current month, I want to set default value in my enumeration list to value like a current month...
I didn't find any examle accorthing to this, or maybe I missed it out.
Hope you understood me now..

Regards,

Hi, as I already tried to express in earlier posts, for Enumerations you have to pass the enumeration literals as string. You have to look up the enumeration literals in the Process Configuration Source, or use a script to spy at the labels and values.

The script below defaults the Risk attribute to medium.


/***********
 * 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.DefaultValueProvider");

(function() { dojo.declare("com.example.DefaultValueProvider", null, {

    getDefaultValue: function(attribute, workItem, configuration) {

        return "Risk.literal.l3"

    }
});

})();


Permanent link
 Hi Ralph,

thank you very much for your pattient and help.

I am totaly newbie in scripting on work item attributes, and I must complete some implementations in these week.
Also, I totally missed out the Default value based on Script, I didn't see it in menu, that is what I was missing to complete this.

Anyway, thanks again.

Regards,

0 votes

Comments

You should have performed our workshop. It would probably have been quicker than waiting for answers here. In case you have not seen it:



Permanent link
 Yes, I know,

but in this case, this was better way for my situtation, and I clearly understood some things based on decaling dojo functions etc etc...


0 votes

Your answer

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

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 12,020

Question asked: Mar 22 '13, 11:22 a.m.

Question was seen: 7,362 times

Last updated: Mar 26 '13, 11:20 a.m.

Confirmation Cancel Confirm