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

Setting default values for Timestamp Custom Attribute

Hi everyone.

I've spent some hours with this issue and I haven't been able to find a solution, so I hope to find help in this forum :)

I've declared a custom attribute with a script-based default value, returning the current date. So far so good.

Then, in my work item presentation I've inserted two fields: one of them is text-based, and the other one, a Timestamp. Both of them get their default values from the same attribute and the same script, but when I create a new Work Item, the text-based field displays the default value properly (a string with the current date), but the Timestamp shows the string 'None', and it's still needed to pick a Date to fill the field.

Does anyone know how to set a default value to a Timestamp presentation?


Thanks in advance.


Dani G.

0 votes



10 answers

Permanent link
Hi Dani,

I tried several formats and I will most likely look into the work items if this is known. If not I will create an enhancement request.

The wiki states it should work. Please note also the wiki states that certain things don't work. Contributors don't work either.

1 vote


Permanent link
Hi,

We need to set the Time in milliseconds for the TimeStamp attribute. hence, the following statements should work.
var now = new Date();
var newDate = today.getTime() + "";
return newDate;

1 vote

Comments
Thank you for your help.... I got that working !!!


Permanent link
Hi Daniel,

I followed https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Default_values to do the same. My code looked like:


dojo.provide("com.example.CurrentDateDefaultValueProvider");

dojo.require("dojo.date"); // We need the date class from Dojo to compare two dates
dojo.require("dojo.date.stamp"); // We need the stamp class to work with ISO date strings

(function() {
dojo.declare("com.example.CurrentDateDefaultValueProvider", null, {

getDefaultValue: function(attribute, workItem, configuration) {

var now=new Date();
var date= dojo.date.stamp.toISOString(now, {milliseconds:true, zulu:true});
console.log("Now is: " + date);
return date;
}
});
})();



Unfortunately I have the same effect as you describe in the default value provider. The Eclipse client log shows the error below and I assume this is a bug in the experimental Javascript engine:




!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2011-10-25 14:03:15.544
!MESSAGE LOG: Now is: 2011-10-25T12:03:15.532Z

!ENTRY com.ibm.team.workitem.common 4 0 2011-10-25 14:03:15.546
!MESSAGE Error invoking default value provider 'com.ibm.team.workitem.valueproviders.DEFAULT_VALUE_PROVIDER._YUUP8P76EeCRy-8MDpVeRg'
!STACK 0
java.lang.NumberFormatException: For input string: "2011-10-25T12:03:15.532Z"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:63)
at java.lang.Long.parseLong(Long.java:427)
at java.lang.Long.parseLong(Long.java:476)
at com.ibm.team.workitem.common.internal.model.TimestampAttributeType.valueOf(TimestampAttributeType.java:34)
at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.convert(ScriptAttributeValueProvider.java:111)
at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.getDefaultValue(ScriptAttributeValueProvider.java:65)
at com.ibm.team.workitem.common.internal.attributeValueProviders.AttributeValueProviderRegistry$SafeDefaultValueProvider.getDefaultValue(AttributeValueProviderRegistry.java:83)
at com.ibm.team.workitem.common.internal.model.impl.AttributeImpl.getDefaultValue(AttributeImpl.java:889)
at sun.reflect.GeneratedMethodAccessor56.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at com.ibm.team.repository.common.internal.util.ItemStore$ItemInvocationHandler.invoke(ItemStore.java:597)
at $Proxy24.getDefaultValue(Unknown Source)
at com.ibm.team.workitem.common.internal.WorkItemCommon.createWorkItem(WorkItemCommon.java:207)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.createNewUnconnected(WorkItemWorkingCopyRegistry.java:586)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.connectNew(WorkItemWorkingCopyRegistry.java:580)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyManager.connectNew(WorkItemWorkingCopyManager.java:94)
at com.ibm.team.workitem.client.WorkItemOperation.run(WorkItemOperation.java:230)
at com.ibm.team.workitem.client.WorkItemOperation.run(WorkItemOperation.java:189)
at com.ibm.team.workitem.rcp.ui.internal.actions.NewWorkItemAction$2.runProtected(NewWorkItemAction.java:338)
at com.ibm.team.foundation.client.util.FoundationJob.run(FoundationJob.java:68)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

0 votes


Permanent link
Hi, Ralph,

Thank you for answering. It seems that Timestamp container has an odd behavior dealing with customization. At least, now I know that it isn't only me :)

I'll continue looking for a solution (or at least, a workaround), and if I find it, I'll post it in here.

Thanks.


Dani.

0 votes


Permanent link
Hi, Ralph,

Ok then, I was going crazy :)

Thank you so much for your help.


Regards.


Dani.

0 votes


Permanent link
Hi Daniel,

just to let you know, there was a work item for it and it is fixed - I checked default value provider - in 3.0.1.1.

0 votes

Comments
Hi Ralph, Thanks for the above script on default value: current date I have a requirement to set default value of "to_date" attribute (time stamp) as 15th of current month& year. with ur script i was able to get default value as current date, but Pls let me know the modification which i need to make in script to "mask the day with 15" and pass result. !ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2012-07-19 12:31:51.125 !MESSAGE LOG: Now is: 2012-07-19 T07:01:51.123Z This log shows the result as current date. my requirement is to mask 19 with 15 and pass the result.

Hi Ralp, Im using RTC 3.0.1.3 but i still have the same difficulty mentioned above in writing the date value to the workitem. My script is able to fetch it properly, but unable to write it to the workitem due to" java.lang.NumberFormatException: For input string"


Permanent link
Hi, Ralph.

Thanks for your help. I'll try installing 3.0.1.1.


Regards.


Daniel Garcia

0 votes


Permanent link
 I'm using RTC 3.0.1.3 server and client. I get the same error mentioned above while trying to return the date value.
Can anyone help me on how to fix this ?

0 votes


Permanent link
 Hi Ralph,

I'm using Calculated Value (RTC 4.0 RC0) for a timestamp attribute and have the same problem when the workitem is created. On following actions (i.e. change state, change attribute value, etc.) it works fine.
Any idea?

amit.

0 votes


Permanent link
Amit, I don't have an idea. I didn't see the posts above, probably due to the conversion to the new format. Unfortunately I have no time to look into this right now.

0 votes

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

Question asked: Oct 25 '11, 6:36 a.m.

Question was seen: 16,490 times

Last updated: Aug 22 '12, 10:03 a.m.

Confirmation Cancel Confirm