It's all about the answers!

Ask a question

Setting default values for Timestamp Custom Attribute


Daniel Garcia (4911013) | asked Oct 25 '11, 6:36 a.m.
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.

10 answers



permanent link
Ralph Schoon (63.1k33646) | answered Oct 25 '11, 11:19 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.

permanent link
Muthukumar C (32712833) | answered Aug 06 '12, 5:17 a.m.
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;


Comments
Pavithra Kasturirangan commented Aug 06 '12, 8:34 a.m.

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


permanent link
Ralph Schoon (63.1k33646) | answered Oct 25 '11, 8:10 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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)


permanent link
Daniel Garcia (4911013) | answered Oct 25 '11, 10:45 a.m.
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.

permanent link
Daniel Garcia (4911013) | answered Oct 25 '11, 11:51 a.m.
Hi, Ralph,

Ok then, I was going crazy :)

Thank you so much for your help.


Regards.


Dani.

permanent link
Ralph Schoon (63.1k33646) | answered Oct 27 '11, 12:59 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.

Comments
Gowra chandra varma commented Jul 19 '12, 3:34 a.m.

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.


Pavithra Kasturirangan commented Aug 06 '12, 4:57 a.m.

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
Daniel Garcia (4911013) | answered Nov 02 '11, 4:35 a.m.
Hi, Ralph.

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


Regards.


Daniel Garcia

permanent link
Pavithra Kasturirangan (42955956) | answered Aug 05 '12, 8:26 a.m.
 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 ?


permanent link
Amit Kravzov (1351616) | answered Aug 20 '12, 11:34 a.m.
 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.

permanent link
Ralph Schoon (63.1k33646) | answered Aug 22 '12, 10:03 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Aug 22 '12, 10:03 a.m.
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.

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.