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

Return timestamp into custom attribute

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;
        }
    });
})();

0 votes



One answer

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

        }
    });
})();
    

0 votes

Comments
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?

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.

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");

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.example.ValueProvider", null, {

    getValue: 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;

    }
});

})();

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  


 

 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")); 


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

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: Nov 24 '20, 10:41 a.m.

Question was seen: 1,357 times

Last updated: Dec 07 '20, 4:52 p.m.

Confirmation Cancel Confirm