Scrip based validation
![]()
Pankaj Sharma (40●11●70)
| asked Dec 08 '15, 8:50 a.m.
edited Dec 08 '15, 9:28 a.m. by Ralph Schoon (63.3k●3●36●46)
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
![]()
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 :
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
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.