It's all about the answers!

Ask a question

How do I calculate the summary field based on the custom attribute value in RTC using java script ?


Amit Saxena (3111516) | asked Jul 03 '12, 8:05 a.m.
edited Jul 03 '12, 8:25 p.m. by Geoffrey Clemm (30.1k33035)
I have two custom attributes :  A and B

Any Idea  how to calculate the summary field based on the custom attribute value in RTC using  script based calculated values

6 answers



permanent link
Fausto Lemos (16811518) | answered Jul 03 '12, 8:30 a.m.
hope this helps!

https://jazz.net/wiki/bin/view/Main/AttributeCustomization#ScriptBasedNotes

permanent link
Amit Saxena (3111516) | answered Jul 03 '12, 8:55 a.m.
Hi Fausto,

Thanks for providing me the link. I have been using the same link to create the script:

I have two attributes :

Component  name ( id: component_name)
Component  version ( id: component_version)

and I want to combine both in to summary

Here is my Script:
--------------------



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

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

        getValue: function(attribute, workItem, configuration) {
               
           
            var component = workItem.getValue(component_name);
            var version = workItem.getValue(component_version);
            var result+= component + "  v" + version;
           
            return result;
           
           
           
        }
    });
})();


am i doing something wrong here ?


Comments
Fausto Lemos commented Jul 03 '12, 9:23 a.m.

Did you set this ValueSet for Summary field and added "component_name" and "component_version" as dependencies?


permanent link
Dinesh Kumar B (4.1k413) | answered Jul 03 '12, 9:04 a.m.
JAZZ DEVELOPER
edited Jul 03 '12, 9:06 a.m.
when I use the custom attributes i use the below two points

1.  use the ID of the attribute and not the name
2.  use the ID from within double quotes

for an attribute named Criticality with an ID rcstlt.ms.criticality
var rCrit = workItem.getValue("rcstlt.ms.criticality");
gets me the value

the rest of your script looks fine to me.

permanent link
Amit Saxena (3111516) | answered Jul 03 '12, 10:12 a.m.
Hi,
I am not using the name i am using the ID
i have put "" around the id  now

also  I have already set this ValueSet for Summary field and added "component_name" and "component_version" as dependencies

it is still not working.

I am using the in built summary attribute is that a problem.




permanent link
Fausto Lemos (16811518) | answered Jul 03 '12, 6:27 p.m.
At https://jazz.net/wiki/bin/view/Main/AttributeCustomization#ScriptBasedNotes

Only values of the following attribute types can be safely read by and returned from scripts:
    • Short String
    • Medium String
    • Large String
    • Integer
    • Long
    • Boolean
    • Timestamp as an ISO-8601 standard string. Use dojo.date.stamp to convert a Javascript Date object to and from an ISO-8601 string. When converting a Date object to a string set the milliseconds and the zulu options to true.
      • To convert the value of a timestamp attribute with the id attributeId to a Date object use:
        var date= dojo.date.stamp.fromISOString(workItem.getValue(attributeId));
      • To convert a Date object to an ISO-8601 string use:
        var string= dojo.date.stamp.toISOString(date, {milliseconds:true, zulu:true});
    • Limited support for Enumeration. See the Working with Enumerations section for more information about using Enumerations in scripts.
    • Limited support for Items

The summary field type is "Medium HTML" so will not work...

permanent link
Dinesh Kumar B (4.1k413) | answered Jul 04 '12, 4:12 a.m.
JAZZ DEVELOPER
edited Jul 04 '12, 4:27 a.m.
Your code works for me when i modify the line:
var result+= component + "  v" + version;
to
var result = component + "  v" + version;

and use double quoted attribute ids, for reference here is the code which worked for me:

the code
dojo.provide("com.example.Calculate_Component_Summary");

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

        getValue: function(attribute, workItem, configuration) {
              
          
            var component = workItem.getValue("component_name");
            var version = workItem.getValue("component_version");
            var result = component + "  v" + version;
          
            return result;
        }
    });
})();

the attribute types
and the component summary is the built-in summary type
component name and version are of small string type

the dependencies
the summary attribute has dependency set on both component version and component name


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.