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

How can I set Due Date with a Calculated Value.

Hi,
I want to set Due Date with some specific business rules. It will calculate depending on Severity and Priority. I wrote the script below but it doesn't work.
Thank you.

dojo.provide("org.example.workitems.providers.LatenessIndicator");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");

(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;

dojo.declare("org.example.workitems.providers.LatenessIndicator", null, {

    getValue: function(attributeId, workItem, configuration) {

        // Get the creation date and the current date and compute the difference in days.
        var DueDate= dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.DUE_DATE));
var currentDate = new Date();
DueDate = Date.now();

        // Return a string that indicates whether the completion of this work item is on time
        // or not based on its severity and how much time has passed since it was created.

        var severity = workItem.getValue(WorkItemAttributes.SEVERITY);
var priority = workItem.getValue(WorkItemAttributes.PRIORITY);
//console.log("Basladi");
//Priority l02 = Low, l07=Medium, l11=High
//Severity l02 = Minor, l03=Normal, l04=Major
var s_multiplier = 4;
var p_multiplier = 4;
if ((severity === "severity.literal.l02")) {
s_multiplier = 3;
        } else if ((severity === "severity.literal.l03")) {
s_multiplier = 2;
        } else if ((severity === "severity.literal.l4")) {
s_multiplier = 1;
        } else {
            s_multiplier = 4;
        }
if ((priority === "priority.literal.l02")) {
p_multiplier = 3;
        } else if ((priority === "priority.literal.l07")) {
p_multiplier = 2;
        } else if ((priority === "priority.literal.l11")) {
p_multiplier = 1;
        } else {
            p_multiplier = 4;
        }
DueDate.setdate() = Date.now() + (s_multiplier * p_multiplier); 
return "";
    }
});
})();

0 votes


Accepted answer

Permanent link
You have to calculate a date and return it as string. For example
 var date = Date.now() + (s_multiplier * p_multiplier); // Not sure this is syntactically correct.
 return dojo.date.stamp.toISOString(date, {milliseconds:true, zulu:true});
Kurtulus YILDIRIM selected this answer as the correct answer

0 votes

Comments

Hi Ralph,
I am getting "Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot find function getUTCFullYear in object 1403532234081. ({"Bundle-SymbolicName":"org.dojotoolkit.dojo", "path":"\resources\date", "name":"stamp.js"}#120)" error, when I use return dojo.date.stamp.toISOString(returnDate, {milliseconds:true, zulu:true}); " and returndate value is 1403532234081.
Thank you.

That is odd. I have found this code 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("com.team.example.CurrentDate");

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.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;

    }
});

})();

Not sure what goes wrong. Maybe the calculation?

Hi Ralph,
Yes, you are right. When I did calculation, date automatically is being converted to long. I used dojo.date.add instead of it.
Now, it is working. Thank you very much.


One other answer

Permanent link
dojo.provide("org.example.workitems.providers.duedatesetter");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date");
dojo.require("dojo.date.locale");
dojo.require("dojo.date.stamp");

(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;

dojo.declare("org.example.workitems.providers.duedatesetter", null, {
    getValue: function(attributeId, workItem, configuration) {
var DueDate= dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.DUE_DATE));

        var severity = workItem.getValue(WorkItemAttributes.SEVERITY);
var priority = workItem.getValue(WorkItemAttributes.PRIORITY);

//Priority l02 = Low, l07=Medium, l11=High
//Severity l2 = Minor, l3=Normal, l4=Major
var s_multiplier = 1;
var p_multiplier = 1;
if ((severity == "severity.literal.l2")) {
s_multiplier = 3;
        } else if ((severity == "severity.literal.l3")) {
s_multiplier = 2;
        } else if ((severity == "severity.literal.l4")) {
s_multiplier = 1;
        }
if ((priority == "priority.literal.l02")) {
p_multiplier = 3;
        } else if ((priority == "priority.literal.l07")) {
p_multiplier = 2;
        } else if ((priority == "priority.literal.l11")) {
p_multiplier = 1;
        }
var returnDate = new Date();
returnDate=dojo.date.add(returnDate, "day", s_multiplier * p_multiplier);
return dojo.date.stamp.toISOString(returnDate, {milliseconds:true, zulu:true});
    }
});
})();

0 votes

Comments

Glad you got it working.

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
× 10,941

Question asked: Jun 17 '14, 4:41 a.m.

Question was seen: 3,662 times

Last updated: Jun 17 '14, 10:55 a.m.

Confirmation Cancel Confirm