Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

A validator script seems to be working but the work item is saved even if the script validation is not passed

I have two attributes, an attribute of type "enumeration"  and an attribute of type "Date". I need to make sure that the Date attribute is not set to any value if a specific value of the enumeration is picked up.

For that purpose I did the following:
- I created a validation script to return an ERROR and display a message.
- I configured the Date attribute by setting the validation script for it and setting the enumeration attribute as a dependency.
- I add Attribute Validation as a precondition.

In my test, I can see that the error icon is showing up and the message is displayed. However, the workitem can be saved normally.

I went through many questions on the forum, and followed some advice, by for example, removing the scripts that I don't need, but I still have the same issue.

I'm working on RTC v6.1 and below is the script:
dojo.provide("com.example.FinancialBenefitStartDateValidator");
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

dojo.require("dojo.date");
dojo.require("dojo.date.stamp");

(function() {

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

    dojo.declare("com.example.FinancialBenefitStartDateValidator", null, {
    validate: function(attributeId, workItem, configuration) {
    var attrValue = dojo.date.stamp.fromISOString(workItem.getValue("BenefitsStartDate"));  // this is the date value
var financialBenefitType = workItem.getLabel("BenefitType");  // this is the enumeration value
var message = 'This attribute should be set only when "Financial Benefit Type" is set to any value other than the default "No Financial Benefit"';
   
if (financialBenefitType == "No Financial Benefit" && attrValue) {
return new Status(Severity["ERROR"], message);
}  else {
return Status.OK_STATUS;
}
    }
});
})();

0 votes


Accepted answer

Permanent link

Similar questions have been asked quite many times on this forum. There are two critical things that you need to do to achieve the desired result.
1. The script returns the correct result on the server side - the validation script runs on both the client side and server, and in some rare cases the script can return different results.
2. The precondition "Attribute Validation" is configured for the correct role - this is important when a user has multiple roles. In other words, you need to ensure the script does get executed on the server side.

Abdelrahman Hassan selected this answer as the correct answer

0 votes

Comments

Also this looks odd:

financialBenefitType == "No Financial Benefit" && attrValue


attrValue is a string and not a boolean.

@Donald, thank you for your helpful comment. It really helped to figure out the issue. I added the solution in a separate answer.

@Ralph, thank you for your comment. I'm using this check "if (attrValue)" to make sure that my attribute has a meaningful value which is not (null, undefined, NaN, empty string (""), 0, false)
Please refer to the following question on stackoverflow:
https://stackoverflow.com/questions/5515310/is-there-a-standard-function-to-check-for-null-undefined-or-blank-variables-in


One other answer

Permanent link

The issue is resolved, details are below.

Although the server was fine in client side, it wasn't really running in the server side and I was able to know that by checking ccm.log file.

I found the following error in "ccm.log" file:
ERROR com.ibm.team.workitem.common - Error invoking validator FinancialBenefitStartDateValidator associated with the attribute 'Financial Benefit Start Date' in the project area with id '_dEidkOTzEeWNItGq29_JNQ'.You can link to the project area definition using a URL similar to https://thehostname:9443/jazz/process/project-areas/_dEidkOTzEeWNItGq29_JNQ, where the host name, port and jazz context are configured for your installation. Contact your project area administrator for assistance.
com.ibm.team.repository.common.TeamRepositoryException: Process Attachment /workitem/scripts/common/mandatory-blocked-reason.js does not provide a dojo type

The first line states that my script is not invoked and the last line states that there is a problem with another script.
Therefore, I deleted the other script that has the problem (as I didn't need it) and the issue was resolved.

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 152

Question asked: Dec 07 '17, 8:22 p.m.

Question was seen: 3,403 times

Last updated: Dec 11 '17, 10:08 p.m.

Confirmation Cancel Confirm