Calculated value script to check if a contributor list has 'no value' or one one or more names assigned.
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
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 usegetStringRepresentation
. Assumingdecimal
is aBigDecimal
instance:var decimalString= decimal.getStringRepresentation();
-
To compare
BigDecimal
objects usecompareTo
. Returns: -1, 0, or 1 as this instance is numerically less than, equal to, or greater than argument. Assumingdecimal
andotherDecimal
areBigDecimal
instances:var comparedValue= decimal.compareTo(otherDecimal);
-
To evaluate for equality with
BigDecimal
objects useequals
. Returns: true if the instances are numerically equal. Assumingdecimal
andotherDecimal
areBigDecimal
instances:var areEqual= decimal.equals(otherDecimal);
-
To validate a string use (returns true iff decimalString is valid):
- Boolean
-
Timestamp as an ISO-8601 standard string. Use
dojo.date.stamp
to convert a JavascriptDate
object to and from an ISO-8601 string. When converting aDate
object to a string set themilliseconds
and thezulu
options to true.-
To convert the value of a timestamp attribute with the id
attributeId
to aDate
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});
-
To convert the value of a timestamp attribute with the id
- 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.
2 other answers
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()