Read-only attribute for condition is preventing save work item
I am using RTC 4.0.1. I have created a script-based condition and configured precondition "Read-only attribute for condition" for a specific role.
When I want to save a work item, even if my javascript is always returning false, I always get an error that says the attribute is not modifiable (this attribute is selected as the read-only attribute).
Here is the content of my original script:
dojo.provide("com.test.Condition.assignedManagerMatch");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;dojo.declare("com.test.Condition.assignedManagerMatch", null, {
matches: function(workItem, configuration) {
var owner = workItem.getValue(WorkItemAttributes.OWNER);
var modifiedby = workItem.getValue(WorkItemAttributes.MODIFIED_BY);
if (owner != modifiedby) {
return true;
}
return false;
});
})();
At this point, I am not sure if there is a problem with my javascript or there is a bug in the precondition.
Is anyone else experiencing the same problem?
Accepted answer
The "Read-only attribute for condition" precondition verifies that work items match the condition selected in the configuration. A sample 'Condition' script is as below. Could you try a simple version below and see if it works? If it works, I would try to print out the value of owner and modifiedby to compare.
* Licensed Materials - Property of IBM
* (c) Copyright IBM Corporation 2011. All Rights Reserved.
*
* Note to U.S. Government Users Restricted Rights:
* Use, duplication or disclosure restricted by GSA ADP Schedule
* Contract with IBM Corp.
*******************************************************************************/
dojo.provide("com.example.Condition");
(function() {
dojo.declare("com.example.Condition", null, {
matches: function(workItem, configuration) {
return true;
}
});
})();
/*******************************************************************************
* Licensed Materials - Property of IBM
* (c) Copyright IBM Corporation 2011. All Rights Reserved.
*
* Note to U.S. Government Users Restricted Rights:
* Use, duplication or disclosure restricted by GSA ADP Schedule
* Contract with IBM Corp.
*******************************************************************************/
dojo.provide("com.example.Condition");
(function() {
dojo.declare("com.example.Condition", null, {
matches: function(workItem, configuration) {
return true;
}
});
})();
4 other answers
Hi Alicia,
I would check if you did not select the attribute read only somewhere else. I would also chack https://jazz.net/library/article/1093 Lab 5 for hints about debugging or at least using the log. That lab is also a good resource to learn.
I would dump the user ID's you are getting and also check JavaScript as there is an === available as well.
Make sure to upload your latest condition script as well. If you do so, you must close the work item and open it again to get your editor recognize the new script version. And as suggested by Piotr, I would first return a false without any other processing and make sure it works.
As an after thought check the Logs, it is not CCM.log you have to look at, The workshop Lab 5 mentioned above explains where to find the log you are looking for. In your case it is most likely the server version.
I would check if you did not select the attribute read only somewhere else. I would also chack https://jazz.net/library/article/1093 Lab 5 for hints about debugging or at least using the log. That lab is also a good resource to learn.
I would dump the user ID's you are getting and also check JavaScript as there is an === available as well.
Make sure to upload your latest condition script as well. If you do so, you must close the work item and open it again to get your editor recognize the new script version. And as suggested by Piotr, I would first return a false without any other processing and make sure it works.
As an after thought check the Logs, it is not CCM.log you have to look at, The workshop Lab 5 mentioned above explains where to find the log you are looking for. In your case it is most likely the server version.
Comments
And from looking at your script name, in the script you can only access the UID (getValue) or the Name (getLabel) of contributor type attributes. You can not access team membership, nor roles or any other useful information. This is also discussed in Lab 5 of said workshop.
1 vote
Hi Ralph
The script worked correctly after I change getValue to getLabel.
I think there is problem comparing the value of owner and modified by.
Thanks,
Alicia
Alicia,
this is a condition that I did recently and it worked for me.
this is a condition that I did recently and it worked for me.
/******************************************************************************* * Licensed Materials - Property of IBM * (c) Copyright IBM Corporation 2011. All Rights Reserved. * * CorrectedEstimateSetCondition * * Note to U.S. Government Users Restricted Rights: * Use, duplication or disclosure restricted by GSA ADP Schedule * Contract with IBM Corp. *******************************************************************************/ dojo.provide("com.acme.providers.script.CorrectedEstimateSetCondition.js"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); (function() { var doDebug = true; var scriptname = "CorrectedEstimateSetCondition.js"; var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("com.acme.providers.script.CorrectedEstimateSetCondition.js", null, { matches: function(workItem, configuration) { debug("Start"); var correctedEstimate = workItem.getValue("com.acme.wi.attrib.incident.correctedeffort"); debug("correctedEstimate: " + correctedEstimate); if(correctedEstimate==""){ return false; // Nothing to do } debug(" Required"); return true; function debug(display){ if(doDebug){ console.log(scriptname + " " + display); } } } }); })();
Comments
Hi Ralph,
I created following script for disabling time spent attribute. So, my condition is next: If current month is equal to 4, let this attribute be read only.
dojo.provide("com.apisit.disable.timeSpent");
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
dojo.declare("com.apisit.disable.timeSpent", null, {
matches: function(attribute, workItem, configuration) {
var currentDate= new Date();
var day = currentDate.getDate();
var month = currentDate.getMonth() + 1;
var year = currentDate.getFullYear();
if(month === 4){
return true;
}
else
{
return false;
}
}
});
})();
I also created Condition on Attribute Customization, and loaded this script, and after that, I created Read-Only Attributes For Condition on Operation Behavior, and chose Time spent for this Condition, but this doesn't work for me.
Am I doing something wrong?
It works now, I removed attribute from input parameters function.
Thanks,
Always start from downloading the sample if you are not sure Milan.
Hi All,
I have similar kind of problem but i'm not able to resolve it, i have a attribute which has two radio button "Yes" & "No" and the text field.
Validation which i need to implement is if user click on "Yes" then text field become mandatory and if user click "No" then text field become read-only.
My script works fine if user click YES then text field become mandatory but if user click NO then text field doesn't become read-only.
Please help me to implement read-only part in following script:
dojo.provide("org.example.workitems.providers.RFCandEPMOReference1");
dojo.provide("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("org.example.workitems.providers.RFCandEPMOReference1" , null, {
matches: function(workItem, configuration){
var rfc = workItem.getValue("ThisRFCisProject.attribute");
console.log(rfc);
if(rfc == "enumeration.ThisRFCisProject.literal.l4"){
return true;
}
return false;
}
});
})();
Comments
Piotr Aniola
Apr 17 '13, 5:19 a.m.Hello,
can you check with the sample script provided with RTC?
Milan Krivic
Aug 18 '15, 5:48 p.m.I wanted to ask if there is possible to make some work item attribute read only based on another chosen wi attribute.
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Apr 17 '13, 10:32 a.m.Milan, that is what Alicia is trying. This is possible with 4.x using a JavaScript based condition. See https://jazz.net/wiki/bin/view/Main/AttributeCustomization.
Antonio Gracia
Jan 14 '16, 11:02 p.m.Hello,
I have the same problem here
this is our script
ReadOnlyAttributesCondition.js
dojo.provide("com.ibm.san.workitem.ReadOnlyAttributesCondition");
(function() {
var PARAMETERS_KEY = "parameters";
var ATTR_ID_KEY = "attrId";
var ATTR_CONDITION_KEY = "attrCondition";
dojo.declare("com.ibm.san.workitem.ReadOnlyAttributesCondition", null,
{
matches : function(workItem, configuration) {
var attrId = configuration.getChild(PARAMETERS_KEY).getStringDefault(ATTR_ID_KEY, "");
var attrValue = workItem.getValue(attrId);
var attrCondition = (configuration.getChild(PARAMETERS_KEY).getStringDefault(ATTR_CONDITION_KEY,"false") == "true");
var result = (attrValue == attrCondition);
return result;
}
});
})();
and the other ReadOnlyCheckRecurrentCondition.js
dojo.provide("com.ibm.san.workitem.ReadOnlyCheckRecurrentCondition");
(function() {
var PARAMETERS_KEY = "parameters";
var ATTR_ID_KEY = "attrFactPref";
dojo.declare("com.ibm.san.workitem.ReadOnlyCheckRecurrentCondition", null,
{
matches : function(workItem, configuration) {
var attrIdFactPref = configuration.getChild(PARAMETERS_KEY).getStringDefault(ATTR_ID_KEY, "");
var attrValue = workItem.getValue(attrIdFactPref);
var result = (attrValue == "");
return result;
}
});
})();
we need them three times because we have three checks and three textfields that we need to put in read only
If we click save after delete with x button the data it does't work because
the script catch the change, it put its read only true when we debug, but visually no .
I hope you understand me, sorry for my bad English.
If you need more info please tell me.
Thanks in advance