It's all about the answers!

Ask a question

JavaScript condition based on value of custom attribute?


Susan Hanson (1.6k2185193) | asked Aug 06 '13, 6:43 a.m.
I'm doing a JavaScript-based condition to be used to determine dynamically if an attribute should be required, based on
https://jazz.net/library/article/1003/#conditions

We want a custom String field (Submitter phone) to be required whenever a custom Integer field (DevWorksID) is equal to 0.

I've looked in a couple other places:
https://jazz.net/wiki/bin/view/Main/AttributeCustomizationExamples#Determine_the_value_set_for_an_e
https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Conditions

and everything seems to only work off built-in attributes.
Is this possible?  I'm on 4001.

Thanks,
Susan

Accepted answer


permanent link
Indradri Basu (1.8k1514) | answered Aug 06 '13, 7:17 a.m.
Yes, I have tried conditions with custom attributes and it worked for me.
Here is a dummy script:
dojo.provide("com.example.Condition");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {
    dojo.declare("com.example.Condition", null, {
        matches: function(workItem, configuration) {

         var DWID = workItem.getValue("DevWorksID");
         console.log("HERE IS THE VALUE" + " " + DWID);
          if (DWID=="0") {
            return true;
        }
        else  {
            return false;
       }
        }
    });
})();
Then from Operations Behavior-> Save WorkItems, add the precondition "Required Attribute for Conditions"  and add your new condition for the required attribute(s).


Susan Hanson selected this answer as the correct answer

Comments
Susan Hanson commented Aug 06 '13, 7:18 a.m.

oh geez, now i feel a little silly :-)

Thanks so much!
Susan

Your answer


Register or to post your answer.