It's all about the answers!

Ask a question

Read-only attribute for condition is preventing save work item


Alicia Loh (323) | asked Apr 17 '13, 4:56 a.m.
edited Apr 17 '13, 6:46 a.m. by Ralph Schoon (63.5k33646)
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?



Comments
Piotr Aniola commented Apr 17 '13, 5:19 a.m.

Hello,

can you check with the sample script provided with RTC?


Milan Krivic commented Apr 17 '13, 10:27 a.m. | edited 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.

For example, If I choose some value from enumeration list, I want to make read only or disabled other wi attribute.

Thanks in advance,


Ralph Schoon commented Apr 17 '13, 10:32 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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 commented Dec 30 '15, 12:07 p.m. | edited 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

Accepted answer


permanent link
Kot T. (1.5k11319) | answered Apr 17 '13, 9:41 a.m.
JAZZ DEVELOPER
edited Apr 17 '13, 9:46 a.m.
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;
        }

    });
})();
Alicia Loh selected this answer as the correct answer

Comments
Alicia Loh commented Apr 19 '13, 3:03 a.m.

Thanks Kot.  I found that there is a problem when comparing the values retrieved by getValue() function. Not sure if it is only related to contributor type.

4 other answers



permanent link
Ralph Schoon (63.5k33646) | answered Apr 17 '13, 6:51 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.

Comments
1
Ralph Schoon commented Apr 17 '13, 6:54 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.


Alicia Loh commented Apr 19 '13, 3:02 a.m.

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


permanent link
Ralph Schoon (63.5k33646) | answered Apr 17 '13, 10:35 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Alicia,

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
Milan Krivic commented Apr 18 '13, 4:44 a.m. | edited Jan 14 '16, 11:02 p.m.

 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?


Milan Krivic commented Apr 18 '13, 4:52 a.m.

 It works now, I removed attribute from input parameters function.


Thanks,


Ralph Schoon commented Apr 18 '13, 5:38 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Always start from downloading the sample if you are not sure Milan.


permanent link
Sajjad Ali Khan (314152) | answered Aug 18 '15, 4:55 p.m.
 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;
}
});
})();

permanent link
Kurtulus YILDIRIM (681122) | answered Dec 20 '16, 5:27 a.m.
Hi,
In my case it works when I changed return False or True (capital letter).
Thanks.

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.