addDays is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2014 07:49 AM
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.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2014 08:18 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2014 08:57 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2014 09:18 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2014 10:12 AM
Thanks Abhiram.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2014 10:27 AM
If it's working, please mark an answer correct.