addDays is not working

smondal
Kilo Explorer

Hi everyone,

I have written the below piece of code.

bit it is not working.

Can anyone please help me on that.

 

var time=current.u_meeting_date;

  var gdt = new GlideDateTime(time);

  gs.addInfoMessage(gdt);//this is coming

  var timeupdated=gdt.addDays(7);

  gs.addInfoMessage(timeupdated);//org.mozilla.javascript.Undefined@4964c7 error

 

Many thanks in Advance.

9 REPLIES 9

adiddigi
Tera Guru

Basically what you are missing is, addDays doesn't return any value. What addDays does is, it will modify the current object, here gdt by the duration.



So your example will work if you don't use timeupdated, meaning :



var time=current.u_meeting_date;


  var gdt = new GlideDateTime(time);


  gs.addInfoMessage(gdt);//this is coming


  gdt.addDays(7);


gs.addInfoMessage(gdt);


Hi Abhiram,


You are absolutely right.


below code is creating 10 more record that is expected,but what i want more like, u_meeting_date should be increased by 7 days.


fist increment is by 7 days ,next should be 14 days so on....



var loop_max = 10;//assuming integer type.


var i=0;


for (i; i != loop_max; i+=1) {


createRecord();


}


function createRecord() {


  //this function creates a record on the health check table


  var gr= new GlideRecord('u_cab_meeting');


  gr.initialize();


  var time=current.u_meeting_date.getGlideObject();


  var gdt = new GlideDateTime(time);


    gdt.addDays(7);


  gr.u_meeting_date=gdt;


  gr.u_name=current.u_name;


  gr.u_conference_information=current.u_conference_information;


  //etc...


  gr.insert();


}





Many Thanks in Advance


var loop_max = 10;//assuming integer type.



var i=0;



for (i; i != loop_max; i+=1) {



createRecord(i+1);



}



function createRecord(inc) {



  //this function creates a record on the health check table



  var gr= new GlideRecord('u_cab_meeting');



  gr.initialize();



  var time=current.u_meeting_date.getGlideObject();



  var gdt = new GlideDateTime(time);



  gdt.addDays(7*inc);



  gr.u_meeting_date=gdt;



  gr.u_name=current.u_name;



  gr.u_conference_information=current.u_conference_information;



  //etc...



  gr.insert();



}



should work for you.


Thanks Abhiram.


If it's working, please mark an answer correct.