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

Need help with adding days to custom date attribute in calculated value script

I've been tasked with writing a script that will pull a date from a custom attribute called "Finding Date" and adding 'X' number of days depending on the value of another field called 'Risk'. 

When debugging the script the Finding Date and Risk value is found correctly but it's having trouble adding x days to the finding date. 

 If the value from the risk drop list is "High" then 15 days need to be added to the finding date to get the 'Vulnerability Expiration Date"


here's the part of the script that's running into an exception,

//variable for number of days added to High Risk findings
var numberOfDaysToAdd = 15

I've tried both the following formats to get vExpirationDate:

var vExpirationDate = new Date(findingdate.setDate(findingdate.getDate() + numberOfDaysToAdd));
 
and

 var vExpirationDate = findingdate.setDate(findingdate.getDate() + numberOfDaysToAdd);

so if the finding date is 2/22/17 and the number of days to add is 15, the vExpirationDate should = 3/9/17

Both are getting exceptions.  Any help would be appreciated

0 votes


Accepted answer

Permanent link

Hi,

Could you elaborate on what kind of exception you're getting?

A possible cause for the problem might be that the value you are pulling from the custom attribute "Finding Date" is not a proper Date object.

I've also checked the script and it should be working as expected if you're using the first format i.e.

var vExpirationDate = new Date(findingdate.setDate(findingdate.getDate() + numberOfDaysToAdd));

setDate() returns an integer denoting the milliseconds between 1 January 1970 00:00:00 UTC and the given date, so your second format would result in "vExpirationDate" being a large integer instead of a Date object.

Regards,
Andy

Michael Angelastro selected this answer as the correct answer

0 votes

Comments

 Thanks Andy.  The first format worked!  The reason it wasn't working originally was due to one of my variables.  "findingdate" should have been "findingDate"


One other answer

Permanent link

 I would suggest to use dojo/date and use functions such as add and difference and the like: https://dojotoolkit.org/reference-guide/1.10/dojo/date.html . I have used dojo/date to calculate the difference and it worked for me.

0 votes

Comments

 Thanks, Ralph!  I'll use this link for future date calculations

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
× 6,130

Question asked: Feb 22 '17, 11:58 a.m.

Question was seen: 2,225 times

Last updated: Mar 02 '17, 7:24 p.m.

Confirmation Cancel Confirm