In regards to the calculation between two record

RockRsv
Tera Contributor

I need a calculation between two records in my app engine. I am currently working in dev environment - sandbox and needed to get a column which gives the difference between two fields.

as a example:
 

column 1: due date - 08/31/2025
column 2: lead time - 30

output : start date: 08/31/2025 -30 = 07/31/2025

and i want to use this a trigger daily on flows. How i can get this difference in my instance. I tried using formula but not working. my instance is currently not allowing me to script anything. can anybody let me know the logic can be used?

 

Thanks in advance. 

7 REPLIES 7

RockRsv
Tera Contributor

It didn't work for me yet. not sure if i need to have a advance writing access to get this done. currently i am using service now dev sandbox environment

Bhuvan
Kilo Patron

@RockRsv 

 

You can use GlideDateTime to achieve your requirement. 

 

For example, consider below record from Hardware table. For demonstration purpose, take 'purchase date' as the 'start date' in your logic and assume you have a field 'lead time'. You can calculate 'due date' using below script,

 

 

Bhuvan_0-1755329287120.png

Bhuvan_1-1755329323317.png

Bhuvan_2-1755329365725.png

var gr = new GlideRecord('alm_hardware');
gr.addQuery('sys_id','=','0ea9604d3790200044e0bfc8bcbe5d35');
gr.query();
while (gr.next()) 
{
var start_date=gr.purchase_date;
gs.print("Start Date is : " + start_date);
var due_date=new GlideDateTime(gr.purchase_date.getGlideObject());
var lead_time=30;
due_date.addDaysLocalTime(lead_time);
gs.print("Due Date is : " + due_date);
}

 

If this helped to answer your query, please accept the solution and close the thread.

 

Thanks,

Bhuvan

RockRsv
Tera Contributor

RockRsv_0-1755608582477.png

I was trying here @Bhuvan   @GlideFather