Date xxx days from now

airwin77
Kilo Contributor

Anyone have any thoughts or examples of how to get ServiceNow to take any of the gs.(date records) like Now() and add say 2 days to it? What I'm attempting to to do is make it so that the default date that is presented on a request form shows a date that is at least 2 days in the future? Many of the other tools I support and work with I would just do something simple like Now()+2, however from a ServiceNow perspective all that yeilds is the value for today?

I've looked at http://wiki.servicenow.com/?title=GlideSystem and it has several examples of how to script time / hours in the past however it looks like they never thought to add anything that would be useful for days from now?

Likewise I already use scripts that can validate end time is greater than start time, however those really don't help me when it comes to setting a default value for a future date.

Thank in Advance

9 REPLIES 9

anamaria_enea
Kilo Contributor

Hello,

Did you try to use a negative value (for example "gs.daysAgoStart('-5')")?
I made a test and it works!

Regards,
Anamaria


I think there is a slight syntax error in Anamaria's script, no quotes around the number.
gs.daysAgoStart(-5)


airwin77
Kilo Contributor

I had forgotten the negative value piece of ServiceNow, however my current instance doesn't like that script expression so I'm going to try another on a different build and see if it's a build issue.


airwin77
Kilo Contributor

Did you have to change the field type from date/time to string or something else in order to get this to work? When I try the gs.daysAgoStart('-5') or variations of it I can't get any of my versions or instance builds to want to display anything? I tried on a couple Calgary instances, and a Dublin, all had the same result. I also tried adding it as a Javascript:gs.dayAgoStart(-5) with the same results?