- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2019 11:51 PM
Hi everyone,
Completely new to the ServiceNow platform and in the process of undergoing training. So bear with me if this is too basic or obvious.
I'm on Madrid build (Personal Developer instance). In one scenario that I'm working on, the requirement is to set the expiry date to 1 year from today whenever a new record is created. So basically, this is my action plan:
- Create a "after" business rule to run on "Insert"
- In the scripting part, the code I'm using is as follows:
var currentTime = new GlideDateTime();
current.u_allocated_from = currentTime; // this works as intended as the field gets populated with the current date/time
var monthsToAdd = parseInt(gs.getProperty('AllocationExpiry'), 10);
gs.info('Months to add is ' + monthsToAdd); // this works fine as well as I see "12" being printed in the logs
var addTime = currentTime.addMonthsUTC(monthsToAdd);
gs.info('future time is: ' + addTime); // <--- problem area: prints "undefined" in the logs
current.u_allocated_till =addTime; // thus, this fails too
current.update();
Any idea why addMonthsUTC doesn't work?
Thanks,
Nisar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2019 12:01 AM
Hi Nisar,
Are you using scoped app?
Also addMonthsUTC() doesn't return anything
remove that and it should work
remove this
var addTime = currentTime.addMonthsUTC(monthsToAdd);
and update it as below
currentTime.addMonthsUTC(monthsToAdd);
gs.info('future time is: ' + currentTime);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2019 12:01 AM
Hi Nisar,
Are you using scoped app?
Also addMonthsUTC() doesn't return anything
remove that and it should work
remove this
var addTime = currentTime.addMonthsUTC(monthsToAdd);
and update it as below
currentTime.addMonthsUTC(monthsToAdd);
gs.info('future time is: ' + currentTime);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2019 12:11 AM
Yep, you were right. The problem was trying to use a return value when there was none.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2019 12:16 AM
You can try this script, The addTime wont return any value when dot walked.
var currentTime = new GlideDateTime();
current.u_allocated_from = currentTime; // this works as intended as the field gets populated with the current date/time
var monthsToAdd = parseInt(gs.getProperty('AllocationExpiry'), 10);
gs.info('Months to add is ' + monthsToAdd); // this works fine as well as I see "12" being printed in the logs
currentTime.addMonthsUTC(monthsToAdd);
current.u_allocated_till =currentTime.getDate();
current.update();