How do I get this attribute customization working? Setting a state date / time in a Work Item
- Go to administrative page of your RTC server https://your.server.name:9443/ccm/admin.
- Open the Server tab.
- From the left side-bar open Configuration > Advanced Properties
- In the Work Item Component find the Enable Process Attachment Scripts property and set its value to true.
2 answers
I would also be interested in if you got it working.
This is what I have discovered so far.
1. You can get the state of a work item, but you can not (trivially) detect a state change. The only chance is the way you did it: setting the value of the attribute to some value that you can detect as unassigned.
2. For date/timestamp look at the special instructions in https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Using_scripts_for_attribute_cust
Hi, Nigel. I've spent a fair amount of time working with/on your script. I've toyed with dates in scripts before without much success, so I figured I'd help us both out. ;-)
A few notes, first: Date.now() returns a number of seconds, not a Date object so that won't ultimately work. There is a section in the article Ralph posted that talks about date handling -- need to use real Date objects and dojo's date.stamp.toISOString() to return a date RTC will be happy with. Because the script may execute at other times (not just on status changes) I think you missed the case where you want to return the current value so that nothing changes. Since State changes can't be trapped on the client side, you'll need a fair amount of logging during the debugging phases (which you'll probably want to remove later).
Hope this helps. It is not warranted to be bug-free, so use at your own risk:
dojo.provide("defect.calculated.verifyDateTime");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("defect.calculated.verifyDateTime", null, {
getValue: function(attribute, workItem, configuration) {
console.log("Considering appropriate value for verifyDate...");
var returnDate = null;
var verifyState = "5";
var verifyDateTime2 = workItem.getValue(attribute);
var currentState = workItem.getValue(WorkItemAttributes.STATE);
console.log("State is " + currentState + ". Current date is set to " + verifyDateTime2);
if (currentState == verifyState && verifyDateTime2 == null) {
var rightNow = new Date();
console.log("Newly in or returning to verify state, setting date to now");
returnDate = dojo.date.stamp.toISOString(rightNow, {milliseconds:true, zulu:true});
} else if (currentState == verifyState && verifyDateTime2 != null) {
console.log("Already in verified state with date, setting to current value");
returnDate = verifyDateTime2;
} else if (currentState != verifyState && verifyDateTime2 != null) {
console.log("No longer in verified state, clearing verifyDate value");
returnDate = null;
} else {
console.log("Nothing we care about is going on, leaving value as null");
}
console.log("Actually returning " + returnDate);
return returnDate;
}
});
})();
When using the script and catching the transition, the last log message shows:
!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2012-11-08 16:35:45.389
!MESSAGE LOG: Actually returning 2012-11-09T00:35:45.387Z
If you see this, you should be okay. If you are not seeing successful saves, check your server log for NumberFormatException errors meaning you are not quite handling the date data correctly.
Comments
Hi Millard, Thanks for checking it. I used it as is and it did not set the field :-(. I also didn't get a console message out of the Eclipse client. I don't have access to the server console, but will check with someone who should have. Thanks again. Nigel.
I had this working locally yesterday so unless I flubbed something while pasting it in, it should work. The one thing I did that I don't see mentioned in your description is that I made the new attribute dependent on the Status attribute. That may not matter as it should still get called on save.
I would strongly recommend setting up a local server on your personal workstation so that you can have better insight/control for debugging things like this. It's quite easy and free (for fewer than 10 developers). Then you can start the server and test your customizations and have access to all of the logs. And when your poking and prodding and testing has left your project area a bit of a mess, you just make a new one and keep going.
I totally agree with Millard with respect to the test system. For all the reasons he states. That is what a lot of people do and it is easy enough to do.
Millard, I think the script is only called once, if the change in another attribute needs to trigger it again, then the dependency is required as far as I know.
Nigel, are you sure you configured the script for an attribute? If you don't see a console output in the Eclipse client, when creating the work item with the Eclipse client, then something is wrong. You should at least see an error if the scripting is not configured in the server. Which version of RTC are you running?
Comments
Nigel Hopper
Oct 25 '12, 11:28 a.m.Seems I do need the server bouncing for this to take affect which is probably the main reason I'm not seeing anything happening!
Nigel Hopper
Oct 25 '12, 11:30 a.m.Noddy related question. If I manage to customise this attribute in the way that I hope for. Would this work for every user or just for me. Just curious as it talks about local file path and Attachment Path and for this to be valid, it needs to work for everyone.
Millard Ellingsworth
FORUM ADMINISTRATOR / JAZZ DEVELOPER Nov 07 '12, 8:32 p.m.Hi, Nigel. Did you get this working?
Nigel Hopper
Nov 08 '12, 4:16 a.m.Hi Mark/Ralph
Nigel Hopper
Nov 08 '12, 4:17 a.m.Script PT2:
Nigel Hopper
Nov 08 '12, 4:17 a.m.Script pt3