It's all about the answers!

Ask a question

Scrip based validation


Pankaj Sharma (401170) | asked Dec 08 '15, 8:50 a.m.
edited Dec 08 '15, 9:28 a.m. by Ralph Schoon (63.5k33646)
 I am using RTC eclipses 5.0
I am trying to implement a script based validation on a Radio Button (Enumeration list) having value [Done & N/A]
My objective is user cannot save if N/A is selected in the list, below is my script
/*******************************************************************************
* 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.PRValidation");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");

(function() {

var Severity= com.ibm.team.workitem.api.common.Severity;
var Status= com.ibm.team.workitem.api.common.Status;

    dojo.declare("com.example.PRValidation", null, {

        validate: function(attribute, workItem, configuration) {

var attr1_value = '';
attr1_value = workItem.getLabel("com.ibm.tean.attribute.chk1");
if(attr1_value == "N/A")
{
return new Status(Severity["ERROR"], "Atleast one Checklist  needs to be implemented");
}
else
{
return Status.OK_STATUS;
}

      }
    });
})();


I have updated the operation behaviour for Save Work Item Condition and added Attribute Validation Precondition.

But the problem is its showing me a error image (with the tooltip of error message) next to the attribute but its still saving the workitem, How can i prevent it from saving when N/A is selected.

One answer



permanent link
Dinesh Kumar B (4.1k413) | answered Dec 08 '15, 10:20 a.m.
JAZZ DEVELOPER
Radio Button (Enumeration list)

for Enumeration list, supported presentation kinds are
   Picker Enumeration list
or
  Checker Enumeration list

Radio Button presentation is available for Enumeration attributes and not Enumeration list attributes.

so, i assume you have a Enumeration, an attribute of that Enumeration type and its presented as a Radio Button.

With this kind of a setup, with your code piece, I was able to see that the validation is enforced correctly...
Whenever, I set the attribute "com.ibm.tean.attribute.chk1" to N/A, the save is prevented with the following error :

Problem
Invalid value of attribute 'chk1' in work item '309': Atleast one Checklist  needs to be implemented

Reason
Verifies that a work item can only be saved if all attribute values are valid.

where chk1 is the name of the attribute with the id com.ibm.tean.attribute.chk1.

I even tried this with an Enumeration List attribute and it still works fine.

I assume you are applying the validation script directly on the attribute, in that case, one thing I can suggest is to use
attr1_value = workItem.getLabel(attribute);
instead of
attr1_value = workItem.getLabel("com.ibm.tean.attribute.chk1");

the dependency on the attribute id is reduced by this...

If the problem still continues, you may want to raise a ticket with Support with the process template extracted from your problematic project area.

hope this helps

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.