It's all about the answers!

Ask a question

Setting an attribute value from script


Johnson David (2611416) | asked Jul 30 '13, 10:48 a.m.

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



permanent link
Indradri Basu (1.8k1514) | answered Aug 01 '13, 6:27 p.m.
edited Aug 01 '13, 6:54 p.m.
I would agree with Sam and I would doubt if everything can be done in a single script. As per my understanding here is what I think:
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.

permanent link
sam detweiler (12.5k6195201) | answered Aug 01 '13, 9:55 a.m.
you will not be able to do this with a single routine.  you 'might' be able to code multiple functions in a single script file, but RTC has discreet function requests for each action, so you will have to register each separately

default value
current value
changeable or not

permanent link
Dinesh Kumar B (4.1k413) | answered Jul 30 '13, 11:17 a.m.
JAZZ DEVELOPER
multiple attribute customization can be applied on attributes.

along with your condition, you may want to use default value attribute customization to set the default.

Comments
Dinesh Kumar B commented Jul 31 '13, 5:32 a.m.
JAZZ DEVELOPER

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.


Johnson David commented Aug 01 '13, 8:58 a.m.

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 ?

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.