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

Custom Date attribute (Based on Due date value)

Hi All,
           I am trying to create a calculated value script for this:

newdate = duedate + 7 days

I am getting this error:
[ ccm: AsynchronousTaskRunner-1] ERROR com.ibm.team.workitem.common                        - Error invoking value provider 'com.ibm.team.workitem.valueproviders.VALUE_PROVIDER._AzZLYHmpEeK5jqU0rlGqKg'
com.ibm.team.repository.common.TeamRepositoryException: Unexpected exception type
org.mozilla.javascript.EcmaError: TypeError: Cannot call method "getFullYear" of null ({"Bundle-SymbolicName":"org.dojotoolkit.dojo", "path":"\\resources\\date", "name":"stamp.js"}#127)

My script is as below:
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
    dojo.declare("com.ibm.workitems.providers.Date", null, {

        getValue: function(attributeId, workItem, configuration) {               
        console.log("Start..");
        var dueDate = dojo.date.stamp.toISOString(workItem.getValue(WorkItemAttributes.DUE_DATE));       
        var date1= dojo.date.add(dueDate, "day", 7);
        console.log("Now is: " + date1);

    return date1;       

        }

    });

})();

Please advise.

Thanks.

0 votes


Accepted answer

Permanent link
I have once written this script and it 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("org.example.DateValidator_30_days_later");

dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); // To access the work item attributes
dojo.require("com.ibm.team.workitem.api.common.Status"); // To create a status object to return
dojo.require("com.ibm.team.workitem.api.common.Severity"); // To create a severity for the status
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() {
var Severity = com.ibm.team.workitem.api.common.Severity;
var Status = com.ibm.team.workitem.api.common.Status;

var DateValidator = dojo.declare("org.example.DateValidator_30_days_later", null, {

    validate: function(attributeId, workItem, configuration) {
    
        var severity= "ERROR"; 
        var message= "Date must be at least 30 days from now"; 
       
       // Work Item new: not initialized - provides todays date. Once created provides the creation date 
        var beginDate = dojo.date.stamp.fromISOString(workItem.getValue("com.ibm.team.workitem.attribute.creationdate")); 
        // Get the current attribute's value and make a Date object from it
        console.log("I got: ["+workItem.getValue(attributeId)+"]");
        var endDate= dojo.date.stamp.fromISOString(workItem.getValue(attributeId));        
        // Compare the two dates returns negative value due to order
        var compare = -(dojo.date.difference(endDate, beginDate, "day"));
        if (compare>= 30) { // make sure endDate is not earlier than beginDate + 30
            return Status.OK_STATUS;
        } else {
            return new Status(Severity[severity], message + " current value: [" +endDate + "] and difference is " + compare);
        }
    }
});
})();


Ralph Schoon selected this answer as the correct answer

1 vote

Comments

 Hi All,

             This works. Used fromISOString method to retrieve, add method, and then toISOString to convert back and return value to the attribute.

Thanks.

If this works, please accept the answer that helped, so others can use the knowledge.


One other answer

Permanent link
Hi Valli,

Give a try by importing the prerequisites as below
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
These lines should be added before the (function() {  statement.

Regards
Muthu

0 votes

Comments

 Hi Muthu,

                 my code contains the prerequisites already...i just put the main snippet here...


pls try and let me know.

Thanks.

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: Feb 19 '13, 6:12 a.m.

Question was seen: 5,945 times

Last updated: Jan 08 '14, 7:48 p.m.

Confirmation Cancel Confirm