addDaysUTC(1) is updating multiple variables

johnjudd
Tera Contributor

Hi , I have a scheduled job which pulls the end date of record and uses it to create the start date of the next period. However when I use the glidedatetime function addDaysUTC(1) it's adding 1 day to multiple variables , as below ;

var endDCP = cp.u_enddate.getGlideObject();

  gs.info('**** JJ Says endDCP is : ' + endDCP);

  var sDate = cp.u_enddate.getGlideObject();

  gs.info('**** JJ Says sdate is : ' + sDate);

  sDate.addDaysUTC(1);

  gs.info('**** JJ Says sDate Plus 1 is : ' + sDate   + ' and endDCP is ' + endDCP);

log output ;

25-01-2016 10:23:14

25-01 10:23

6 minutes ago

Information**** JJ Says sDate Plus 1 is : 2016-01-16 and endDCP is 2016-01-16*** Script

25-01-2016 10:23:14

25-01 10:23

6 minutes ago

Information**** JJ Says sdate is : 2016-01-15*** Script

25-01-2016 10:23:14

25-01 10:23

6 minutes ago

Information**** JJ Says endDCP is : 2016-01-15

i've tried swapping the order of the variables and putting endDCP after the addDaysUTC statement but it still behaves the same.   Can anyone spot my deliberate mistake please.

1 ACCEPTED SOLUTION

johnjudd
Tera Contributor

After some assistance from a colleague it turns out the issue was down to me not instantiating each variable as a new GlideDateTime, changing this also required a change to using getDisplayValue .. but the long and the short of it is, issue resolved .. pasted the update code in below as that may make more sense 😉



var endDCP = new GlideDateTime();
var sDate = new GlideDateTime();
endDCP.setDisplayValue(cp.u_enddate.getDisplayValue());
sDate.setDisplayValue(cp.u_enddate.getDisplayValue());
sDate.addDaysUTC(1);


which now results (correctly) in the following;


JJ Says sDate Plus 1 is : 2016-01-16 00:00:00 and endDCP is 2016-01-15 00:00:00


View solution in original post

1 REPLY 1

johnjudd
Tera Contributor

After some assistance from a colleague it turns out the issue was down to me not instantiating each variable as a new GlideDateTime, changing this also required a change to using getDisplayValue .. but the long and the short of it is, issue resolved .. pasted the update code in below as that may make more sense 😉



var endDCP = new GlideDateTime();
var sDate = new GlideDateTime();
endDCP.setDisplayValue(cp.u_enddate.getDisplayValue());
sDate.setDisplayValue(cp.u_enddate.getDisplayValue());
sDate.addDaysUTC(1);


which now results (correctly) in the following;


JJ Says sDate Plus 1 is : 2016-01-16 00:00:00 and endDCP is 2016-01-15 00:00:00