- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2016 05:29 AM
Hi
I want to add months to my start date until a target date like for example
var startDate = new GlideDate();
var endDate = new GlideDate();
endDate.setValue('2016-09-09');
while(startDate<=endDate){
//do some processing
startDate.addMonth(1); //this is not an actual method just added here for verbosity
}
basically i have to generate a record for every month between the startDate and endDate
Regards
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2016 05:39 AM
Hi John,
It's not a clean solution, but you could convert the GlideDate object to a GlideDateTime and use addMonthsLocal() or addMonthsUTC(), then convert back to a GlideDate().
It's a bit messy. I'm not sure why GlideDate() doesn't have addDays(), addMonths(), and addYears() - or some variant of that. I wish it did and invite you to open an enhancement request.
Enhancement requests: Tell us how you would improve the ServiceNow product

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2017 04:25 AM
Try this in your script include on line 11 and 12 instead.
var d = gd.getByFormat("dd/MM/yyyy");
return d;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2017 12:31 AM
Thanks Chuck, I copied the GlideDate() value to a GlideDateTime(), then added the specified months. Later used setDisplayValue("dd/MM/yyyy HH:mm:ss") and then getDisplayValue() while retrieving the data back to the client script.
Quite an elaborate process I must say just to add few days to a GlideDate() field...:)
Cheers
Suhas

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2017 04:49 AM
Hi Suhas,
I know - I don't like changing data types like that either just to add a few days. It would be great if the GlideDate class had some of the methods available to GlideDateTime.
I invite you to open an enhancement request! Our product managers DO listen.
Enhancement requests: Tell us how you would improve the ServiceNow product

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2017 09:01 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2016 06:20 AM
Hi John,
Examle:
var inc = new GlideRecord('incident');
inc.addActiveQuery();
inc.addQuery('number','INC0000055');
inc.query();
var date="";
if(inc.next()){
date=inc.opened_at;
gs.print(date);
var datee = new GlideDate();
datee.setValue(date);
datee.addMonths(2);
gs.print(datee.getDate());
}
output:
[0:00:00.004] Script completed in scope global: script
*** Script: 2016-06-30 04:47:23
*** Script: 2016-08-30