Default value

Aniket Shukla
Tera Contributor

Need a script to add 7 days to current date in default value section of date/time variable of record producer.

3 ACCEPTED SOLUTIONS

PrashantLearnIT
Giga Sage

Hi @Aniket Shukla 

 

Use this script to execute - 

javascript: var date = new GlideDateTime(); date.addDaysLocalTime(7); date.getDisplayValue();

PrashantLearnIT_1-1742887053801.png

 

Screenshot below working - 

PrashantLearnIT_0-1742887005690.png

 

********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@Aniket Shukla 

use this

javascript: var myDate; var gdt = new GlideDateTime(); gdt.addDays(7); myDate = gdt.getDate(); myDate;

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

Hi @Aniket Shukla 

 

You can mark multiple answers as correct as well.

********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

View solution in original post

5 REPLIES 5

Valmik Patil1
Kilo Sage

Hello @Aniket Shukla ,

add below code to your default value field of variable.

javascript: var d = new GlideDateTime(); d.addDaysLocalTime(7); d.getDisplayValue();

ex : javascript : var d = new GlideDateTime(); d.addDaysLocalTime(7); d.getDisplayValue();

Note :&colon is colon symbol (:)

Thanks,

Valmik Patil

AniketShukla_0-1742885890828.png

Not working , its showing same date not 7 days ahead.

 

PrashantLearnIT
Giga Sage

Hi @Aniket Shukla 

 

Use this script to execute - 

javascript: var date = new GlideDateTime(); date.addDaysLocalTime(7); date.getDisplayValue();

PrashantLearnIT_1-1742887053801.png

 

Screenshot below working - 

PrashantLearnIT_0-1742887005690.png

 

********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

Hi @Aniket Shukla 

 

You can mark multiple answers as correct as well.

********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************