Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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:
  1. Go to administrative page of your RTC server https://your.server.name:9443/ccm/admin.
  2. Open the Server tab.
  3. From the left side-bar open Configuration > Advanced Properties
  4. In the Work Item Component find the Enable Process Attachment Scripts property and set its value to true.

but do I need the server restarting for it to actually take notice?

0 votes

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.


Thanks, Nigel

Hi, Nigel. Did you get this working? 


You shouldn't need to bounce the server to get this to work. You may need to refresh your client to cause it to pickup process configuration changes (so refresh your web browser or Refresh on the Project Area in Eclipse and the work item). And once you have it working, it should work for everyone.

A quick note on your script: Since it's a value provider script, the invocation arguments include a reference to the attribute. So that opening line could be:

 var verifyDate = workItem.getValue(attribute);

Hi Mark/Ralph


Unfortunately no. Tried a few things but no success. Current state of Script 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");

 

Script PT2:


(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
  dojo.declare("defect.calculated.verifyDateTime", null, {

    getValue: function(attribute, workItem, configuration) {
      var returnDate = null;
/*      var verifyDate = workItem.getValue(WorkItemAttributes.verifyDateTime2); /
      var verifyDateTime2 = workItem.getValue(attribute);
      var currentState = workItem.getValue(WorkItemAttributes.STATE);
       
      console.log("My message");


Script pt3


      if (currentState == "5" && verifyDateTime2 == null) {

        returnDate = Date.now();

      } else if (currentState != "5" && verifyDateTime2 != null) {

        returnDate = null;

      }
      return returnDate;
    }
  });
})(); 

Apologies, limited space to comment! 

showing 5 of 6 show 1 more comments


2 answers

Permanent link
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

0 votes


Permanent link

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.

0 votes

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?

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 6,121

Question asked: Oct 25 '12, 6:46 a.m.

Question was seen: 5,563 times

Last updated: Nov 09 '12, 11:41 a.m.

Confirmation Cancel Confirm