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 ""; } }); })(); |
Accepted answer
Ralph Schoon (63.5k●3●36●46)
| 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 Hi Ralph,
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: Not sure what goes wrong. Maybe the calculation?
Kurtulus YILDIRIM
commented Jun 17 '14, 10:48 a.m.
Hi Ralph,
|
One other answer
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
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.