It's all about the answers!

Ask a question

Java Script Validator for Category type Attribute not working


Ryan McFadden (191218) | asked Dec 14 '18, 1:26 p.m.

I am using RTC 6.0.3 server.  There is a problem with a validator script that is trying to prevent the selection of the top two tiers of a Category type attribute.  The problem is that on the display the little red "!" icon appears on the display when the user selects the TOP category or the NEXT category (as expected) but when the user clicks the Save button, only the TOP category is blocked.  The work item is able to be saved with the NEXT category even though after the save the red "!" icon is still marking the attribute on the display. 

Code is As follows for the validate function of the validator script:

validate: function(attribute, workItem, configuration) {
   var category = workItem.getLabel(attribute);
   var CAT_TOP = "Project Name";
   var CAT_NEXT = "Teams";
   if ((category == CAT_TOP) || (category == CAT_NEXT))
      return new Status(Severity[Severity.ERROR.name], "Select a Valid Team");
   return Status.OK_Status;
}

A workaround that seems to work is to use the UUID of the invalid categories:
   var category = workItem.getValue(attribute);
   var CAT_TOP = "_XXXXXXXX";
   var CAT_NEXT = "_YYYYYYYY";

Using the browser debugging capabilities to step through the code shows that whether I am using the getValue or getLabel configuration there is no change in how the validator script works. 

I don't like to hard-code UUID's in the java script because the UUID is different from project to project and the script has to be modified to put this on the production project after developing and testing the script on the test project. 


Comments
Ryan McFadden commented Jun 13 '19, 8:14 p.m.

If I don't "Accept" any answers, it means I don't have the rank on this forum to give it a thumbs down yet.   

One answer



permanent link
Ralph Schoon (63.1k33646) | answered Dec 17 '18, 3:34 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 It is possible to make attribute customization scripts configurable. It basically uses the same information format that the attribute customization use in general.



This avoids hard coding.

You might also want to try to use Chrome to debug the scripts to better understand the values you are getting.
Finally, check for the equal operator for JavaScript e.g. === vs. == which might or might not contribute to your issue.

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.