Jazz Register Log in
Jazz Forum Welcome to the Jazz Community Forum

Welcome to the Jazz Community Forum

Connect and collaborate with IBM Engineering experts and users

Script-based validator Sample

I wanted to share an example of something I recently did in case someone else wants to use it for their own purposes and build from it.

dojo.provide("org.example.PtsValidator");

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");


(function() {
var Severity = com.ibm.team.workitem.api.common.Severity;
var Status = com.ibm.team.workitem.api.common.Status;
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;

var DateValidator = dojo.declare("org.example.PtsValidator", null, {

    validate: function(attributeId, workItem, configuration) {
   
        // Get the configuration parameters about the severity and error message of this validator
        var severity= configuration.getChild("parameters").getStringDefault("severity", Severity.ERROR.name);
        var messagePts= configuration.getChild("parameters").getStringDefault("messagePts", "");
       
        // Get the story points attribute from the configuration
        var ptsAttr = configuration.getChild("parameters").getStringDefault("ptsAttrID", "");
        var pts = workItem.getValue(ptsAttr);
       
        // Get the current state value
        var state= workItem.getValue(WorkItemAttributes.STATE);
       
        if (state == "com.ibm.team.apt.story.idea") {
            return Status.OK_STATUS;
        } else {
                if (pts == "0") {
                        return new Status(Severity[severity], messagePts);
                } else {
                        return Status.OK_STATUS;
            }
        }
    }
});
})();

Then, in the Eclipse client > a scrum PA, I created a script-base validator and added the parameters to it.

                    <validator id="com.ibm.team.workitem.valueproviders.VALIDATOR._ielBwEDAEeKw0MAxi0hItg" name="ptsValidator" providerId="com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider">
                        <script class="org.example.PtsValidator" path="/workitem/scripts/common/ptsValidator.js"/>
                        <parameters messagePts="Not in new state...Invalid story point value" ptsAttrID="com.ibm.team.apt.attribute.complexity" severity="ERROR"/>
                    </validator>

3 votes

Comments

It would be useful if you described the use case for this so that people could search for it.



One answer

Permanent link
The above validator script checks when changing workflow state to any states other than the 'New' state, if the story point value is 0 pt, it will display the message "Not in new state...Invalid story point value". This script does not check for any specific work item type.

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
× 12,054

Question asked: Dec 10 '12, 3:11 p.m.

Question was seen: 6,473 times

Last updated: Dec 11 '12, 12:44 p.m.

Confirmation Cancel Confirm