debugging calculated value javaScript
Ryan McFadden (19●1●3●18)
| asked Jan 30 '18, 1:21 p.m.
edited Jan 31 '18, 2:58 a.m. by Ralph Schoon (63.3k●3●36●46) I have a calculated value script defined to calculate the number of days between two custom timestamp fields. If the input form defines today's date as the start date and two days from today as the stop date, the result is 2 days as expected. If however I define the start date that is two days in the past, the result is still 2 days. Is there something here that would prevent a date from being defined in the past? What am I missing?
Below is the code that I am using:
dojo.provide("calculateDuration");
(function() {
dojo.declare("calculateDuration", null, {
getValue: function(attribute,workItem, configuration) {
var startMS = startDate.getTime();
var differenceMS = Math.abs(stopMS - startMS);
}
})(); |
Accepted answer
Ralph Schoon (63.3k●3●36●46)
| answered Jan 31 '18, 2:25 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Read:
This is an example for how to compare dates:
/*********** * Licensed Materials - Property of IBM * (c) Copyright IBM Corporation 2011. All Rights Reserved. * * Note to U.S. Government Users Restricted Rights: Ryan McFadden selected this answer as the correct answer
|
2 other answers
Ralph Schoon (63.3k●3●36●46)
| answered Jan 30 '18, 1:47 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER edited Jan 30 '18, 1:48 p.m. You should Gooogle for JavaScript Funktion to calculate with dates and read the documentation about attribute customization in the team wiki. There is also a process enactment workshop in the library you can download and read to get at this information. You have to do a conversion to correctly read and write dates which is described in the attribute customization API and plus and minus is not needed to calculate date differences. Comments Most of the questions around the attribute customization are tagged with attribute-customization. You can try to search for questions with this tag. I have uploaded examples for this kind of stuff, I think. Others too. |
I can see nothing wrong in your code. All you are working on are just numbers, and there is nothing built-in to differentiate between any data and "now". If you are saying you get 2 instead 4, I suspect there is something wrong outside of the code (well, if you simply retrieve the data from a wrong attribute, only you can tell). Adding console.log() in your code will make it easy for you to see.
|
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.