Return timestamp into custom attribute
Michelle Rutkunas (13●2)
| asked Nov 24 '20, 10:41 a.m.
edited Dec 07 '20, 3:21 p.m. by Ralph Schoon (63.3k●3●36●46)
I have a custom attribute with type of timestamp. I am trying to just return the current date into it from calculated value script here:
dojo.provide("cr.DateInitiated.genInfo");
dojo.require("dojo.date"); dojo.require("dojo.date.stamp"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); (function() { dojo.declare("cr.DateInitiated.genInfo", null, { getValue: function(attribute, workItem, configuration) { var currentDate = new Date(); var currentDateString= dojo.date.stamp.toISOString(currentDate, {milliseconds:true, zulu:true}); var date = dojo.date.stamp.fromISOString(currentDateString); return date; } }); })(); |
One answer
Ralph Schoon (63.3k●3●36●46)
| answered Nov 25 '20, 2:27 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
This has worked for me:
/******************************************************************************* * Licensed Materials - Property of IBM * (c) Copyright IBM Corporation 2011. All Rights Reserved. * * Note to U.S. Government Users Restricted Rights: * Use, duplication or disclosure restricted by GSA ADP Schedule * Contract with IBM Corp. *******************************************************************************/ dojo.provide("com.team.example.CurrentDate"); dojo.require("dojo.date"); // We need the date class from Dojo dojo.require("dojo.date.stamp"); // We need the stamp class to work with ISO date strings (function() { dojo.declare("com.team.example.CurrentDate", 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; } }); })(); Comments
Michelle Rutkunas
commented Nov 30 '20, 3:29 p.m.
this was not my question. This code returns a string ... i am asking about returning the date into a timestamp attribute. My code with the line:
var date = dojo.date.stamp.fromISOString(currentDateString);
return date;
it doesn't return anytning... i have it attached to timestamp attribute. So I need it to be in timestamp format. Which i know the ".fromISOString" does, but for some reason it isn't working for me ... so i need to know what else i am missing
That is a working default value for a date or timestamp attribute, as far as I remember. Maybe you are asking the wrong question?
Michelle Rutkunas
commented Dec 07 '20, 9:41 a.m.
I am asking how to return timestamp value into custom attribute (type of timestamp) when using javascript Date(). perhaps its javascript date format ... need to know how to return a date not string.
Ralph Schoon
commented Dec 07 '20, 10:02 a.m.
| edited Dec 07 '20, 10:05 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I already answered. As far as I can tell, this code should return the date for a timestamp attribute, regardless if custom or not. The code below returns the data in calculated and default values. dojo.provide("com.example.ValueProvider");
You convert to the attribute using dojo.date.stamp.toISOString .
You read such attributes and get the date out of them using dojo.date.stamp.toISOString
Ralph Schoon
commented Dec 07 '20, 10:14 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
This reads the attribute value and makes it available as date in the script: var beginDate = dojo.date.stamp.fromISOString(workItem.getValue("com.ibm.team.workitem.attribute.creationdate"));
Michelle Rutkunas
commented Dec 07 '20, 2:21 p.m.
in your example var date is a string ... i need it to be timestamp.
I know that dojo.date.stamp.fromISOString converts the string to date, but i want to be able to put that date in a timestamp attribute ... is this possible ?
You can continue to ignore my answer. Or you try my code out and see that you have to return a string in the right format. I do not care any more. I will unsubscribe from this question.
I am not ignoring your answer. I simply am asking a different question. I have tried your code and it is not what I am asking.
i have a custom attribute that is type timestamp
I am simply trying to put a date into that attribute.
I understand it has to be the right format ... doing the following doesn't put the date in the attribute:
var currentDate = new Date();
var currentDateString= dojo.date.stamp.toISOString(currentDate, {milliseconds:true, zulu:true}); var date = dojo.date.stamp.fromISOString(currentDateString); return date;
I have the code also assigned to a String Attribute, and it works fine. But i need it tto work with a timestamp attribute
I actually ran the example, again before sharing, and it works for me.
showing 5 of 9
show 4 more comments
|
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.