It's all about the answers!

Ask a question

Calculated value script to check if a contributor list has 'no value' or one one or more names assigned.


g k (17148) | asked May 23 '16, 6:05 a.m.
Hope someone can assist with issue when creating a new calculated value script, I want to check whether a Contributor List has 'No values' or one or more names assigned. I do not need to retrieve the assigned values if there are any, merely a Boolean check if the list is 'empty'.

I have an attribute:

Name                                                                                                                                                                   Type                           ID
Whom in the Dev Centre has signed off the scope and user stories (or would sign off the stable draft)?          Contributor List          DevCentreSignOffofRSD


In the following JavaScript for a calculated value Dev Centre Requirements Sign Off RAG, I want to check if this list is empty.

dojo.provide("DCReqSigOff");
(function() {
    dojo.declare("DCReqSigOff", null, {
        getValue: function(attribute, workItem, configuration) {
     var RSDSigOffByDC = workItem.getValue("RSDSignedOffbyDevCentre");
     var StaDraRSD = workItem.getValue("StableDraftRSD");
     var RSDSigOffBy = workItem.getValue("DevCentreSignOffofRSD");
     if (RSDSigOffByDC == true && RSDSigOffBy !== null) return "CriteriaOutcome.literal.l2";
     else if (StaDraRSD == true && RSDSigOffBy !== null) return "CriteriaOutcome.literal.l3";
          else return "CriteriaOutcome.literal.l4";
        }
    });
})();


I have tried various options for the variable RSDSigOffBy  using getValue and getLabel, and checking for a null, empty string or "No value" without success.

Accepted answer


permanent link
Ralph Schoon (63.4k33646) | answered May 23 '16, 7:41 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I have not tried to test reading list type attributes. Not sure if that is even supported.

https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript says the below and does not even list list type variables and I have to assume it does not support it. The Java API would support this however.


  • 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 (since 4.0.1) provided as String. Helper class BigDecimal can be used for operations. Also see Use BigDecimal. Note: The returned string from a script must be a valid decimal string. To ensure your decimal conforms to a jazz decimal attribute type (i.e., 28 precision, 4 scale), use either isValid static method or BigDecimal constructor will throw com.ibm.team.workitem.shared.common.NumberFormatException with an invalid string.
      • To validate a string use (returns true iff decimalString is valid):
        var isValid= com.ibm.team.workitem.shared.common.BigDecimal.isValid(decimalString);
        						
      • To convert a string to a BigDecimal object use (throws NumberFormatException when decimalString is invalid):
        var decimal= new com.ibm.team.workitem.shared.common.BigDecimal(decimalString);
        						
      • To convert a BigDecimal object to a string use getStringRepresentation . Assuming decimal is a BigDecimal instance:
        var decimalString= decimal.getStringRepresentation();
        						
      • To compare BigDecimal objects use compareTo . Returns: -1, 0, or 1 as this instance is numerically less than, equal to, or greater than argument. Assuming decimal and otherDecimal are BigDecimal instances:
        var comparedValue= decimal.compareTo(otherDecimal);
        						
      • To evaluate for equality with BigDecimal objects use equals . Returns: true if the instances are numerically equal. Assuming decimal and otherDecimal are BigDecimal instances:
        var areEqual= decimal.equals(otherDecimal);
        						
    • 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

Currently there is no dedicated API to work with Items or Enumerations and scripts can only use the id of such attributes. If you need additional information, such as the name that corresponds to an Enumeration literal id, you can pass it to scripts using configuration parameters. See the Configuring additional script parameters section for more information.

g k selected this answer as the correct answer

2 other answers



permanent link
Ralph Schoon (63.4k33646) | answered May 23 '16, 6:57 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
In your "Requirement" you have an ID: DevCentreSignOffofRSD

In your Script  you use

var RSDSigOffByDC = workItem.getValue("RSDSignedOffbyDevCentre");

which is a different ID.

A contributor List should return something list like and RSDSigOffByDC == true does not make sense.



permanent link
Marc De Ridder (11) | answered May 23 '16, 7:26 a.m.

Hi Ralph,

The attribute RSDSignedOffbyDevCentre is actually a Boolean, so RSDSigOffByDC == true is correct.

The attribute in question is DevCentreSignOffofRSD , defined in the third var as RSDSigOffBy . 

The above script tests the list with RSDSigOffBy !== null . We have tried varies other checks, including (but not limited to):

RSDSigOffBy.length !== 0

RSDSigOffBy.isEmpty()

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.