It's all about the answers!

Ask a question

How can I set Due Date with a Calculated Value.


Kurtulus YILDIRIM (681019) | asked Jun 17 '14, 4:41 a.m.
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 "";
    }
});
})();

Accepted answer


permanent link
Ralph Schoon (63.1k33646) | answered Jun 17 '14, 5:03 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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

Comments
Kurtulus YILDIRIM commented Jun 17 '14, 10:08 a.m. | edited Jun 17 '14, 10:09 a.m.

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.


Ralph Schoon commented Jun 17 '14, 10:18 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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?


Kurtulus YILDIRIM commented Jun 17 '14, 10:48 a.m.

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
Kurtulus YILDIRIM (681019) | answered Jun 17 '14, 10:50 a.m.
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});
    }
});
})();

Comments
Ralph Schoon commented Jun 17 '14, 10:55 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Glad you got it working.

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.