Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Subtract No of Days from Date field to set New Date in a field (Scoped App)

Rush B
Tera Contributor

I need to Subtract No of Days(integer field) from a Date field to set New Date in a field for a Scoped App using BR please help me with the logic for scoped application to get the new Date.

 

Example

field a -> 2024-02-21 (Type - Date)

field b -> 5 (Type - Integer)

I need to set (a-b) as a date in a field. This has to be done using BR which uses a scoped app table.

 

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Rush B 

 

What is use case, if you provide more details, that will be good. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Sure , Example

field a -> 2024-02-21 (Type - Date)

field b -> 5 (Type - Integer)

I need to set (a-b) as a date in a field. This has to be done using BR which uses a scoped app table. 

Hi @Rush B 

 

https://www.servicenow.com/community/developer-forum/how-do-i-subtract-days-from-a-date-time-field-u...

 

https://www.servicenow.com/community/developer-forum/subtract-days-from-date-time-field/m-p/1540493

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

piyushsain
Tera Guru

Hi @Rush B 

You can use the script

var gdt = new GlideDateTime('fieldA'); //GlideDateTime to be used even if the type of field is date

gdt.addDaysLocalTime(fieldB * -1);

var newDate = gdt.getDate(); // use this newDate to save in the other field
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain