Setting an attribute value from script
Hello Guys,
I am trying to make few fields read only based on condition. I can do it by settting up 'Operational Behaviour' in the project area. Apart from this, before settting up the values read only, i should also be able to set the value to zero. Is it possible to set the value from a js script before setting it to read only. Belwo is the script.
dojo.provide("net.jazz.example.readonly.Condition");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("net.jazz.example.readonly.Condition", null, {
matches: function(workItem, configuration) {
var dropdownvalue = workItem.getValue("dropdown");
console.log("HERE IS THE VALUE" + " " + dropdownvalue);
if (dropdownvalue=="inex.literal.l4")
return true;
}
});
})();
Thanks..Johnson
3 answers
along with your condition, you may want to use default value attribute customization to set the default.
Comments
hi Johnson, feel free to comment the suggestion to use default values did not address your concern. based on your comments, it might give more clarity and others might have more suggestions to provide... if it has helped, you can mark the question as answered by accepting the answer.
Hello Dinesh,
Thank you so much for showing interest!!
Here is the situation right now!!
I have a dropdown that has Include & Exclude options .Below it has two fields which are depended on the dropdowns values
When the user chooses Include , the below two fields should be editable & mandatory
When the user chooses Exclude, the below two fields should become ready only
In another scenario, If the user had entered values in fields, and then the users change the dropdown
the option to Exclude, the values should become zeros before they become read only.
The script i pasted in my question, can only make the fields read only & editable depending on the dropdwon value (the script is based on condition & operational behaviour section has been configured to deal with it)
but cannot make the fields zero before read only is applied
And also i need the fields mandatory when the use chooses Include option from the dropdown
Can we accomidate all the above scenarios in a single script ?
Not sure default values can address the concern ?
One part is already taken care by your script.
To make the attributes mandatory, in the Attribute Customization section you can add a script based Validation which will check if the attribute values are null and then add Attribute Validation precondition from the Operation Behavior section. ( you can find further help in https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Script_Based_Validation)
Now, your comment "In another scenario...." is something sounds contradictory to me. On one hand you are saying that if the value is Exclude then the other attributes will be "readonly" whereas you are trying to change or set the value to 0. May be something to think of if a different approach is easier; however, you can try this with Script based Calculated Values.