How do I get this attribute customization working? Setting a state date / time in a Work Item
We'd like to set the time and date a defect goes into a Verify state. I can see that attribute customization appears to be the solution, but Java Script is very new to me (OK assembly language programmer!) and I cannot even seem to get test date time stamps to appear! Here is where I have got to.
I added an attribute to the defect:
Name = Verify Date
ID = verifyDateTime2
Type = Timestamp
Calculated Value = verifyDateTime
I've added a presentation to the Editor of
Attribute = Verify Date (verifyDateTime2)
Kind = Timestamp
Read Only = True
The script for the Calculated Value is:
/**
* This is for customising an attribute so that when the state of the work item
* is set to Verify, it captures the date / time stamp. Should the state change
* from Verify, it should clear the date / time stamp.
* <action icon="processattachment:/workflow/verify.gif" id="com.ibm.hursley.cicsts.workflow.defects.action.a12" name="Verify" state="com.ibm.hursley.cicsts.workflow.defects.state.s5">
*/
dojo.provide("defect.calculated.verifyDateTime");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
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) {
var verifyDate = workItem.getValue(WorkItemAttributes.verifyDateTime2);
var currentState = workItem.getValue(WorkItemAttributes.STATE);
if (currentState == "5" && verifyDate == null) {
return Date.now();
} else if (currentState != "5" && verifyDate != null) {
return null;
}
return "";
}
});
})();
As to the currentState being 5, that is based on the definition shown in the comment at the top and I have also tried s5 and Verify!
At the moment, I just have an attribute that says None and I cannot see any errors from the script running (not exactly sure where to look!). I have even just tried to get it to set any date, but no joy.
Apologies for the noddy question and probably noddy errors, but I have to start learning somewhere!
Thanks, Nigel.
Update 1:
Hmmm. Think I have come to the conclusion that the script might not be running. If I added console.log("My message"); before the if statement, I get nothing in the .log showing.
I have followed
To use scripts deployed as process attachments you need to enable this functionality:
but do I need the server restarting for it to actually take notice?
showing 5 of 6
show 1 more comments
|
2 answers
Ralph Schoon (63.5k●3●36●46)
| answered Nov 08 '12, 2:09 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Nigel,
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 |
Millard Ellingsworth (2.5k●1●24●31)
| answered Nov 08 '12, 7:05 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER edited Nov 08 '12, 7:42 p.m. 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"); (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..."); console.log("State is " + currentState + ". Current date is set to " + verifyDateTime2); if (currentState == verifyState && verifyDateTime2 == null) { console.log("Actually returning " + 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
Nigel Hopper
commented Nov 09 '12, 3:46 a.m.
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.
Ralph Schoon
commented Nov 09 '12, 11:37 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.
Ralph Schoon
commented Nov 09 '12, 11:41 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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?
|
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.
Comments
Seems I do need the server bouncing for this to take affect which is probably the main reason I'm not seeing anything happening!
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.
Hi, Nigel. Did you get this working?
Hi Mark/Ralph
Script PT2:
Script pt3