Server side client script to calculate date difference between two fields on a form using ATF.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2019 04:23 AM
Hello,
I need to calculate the time duration between two fields using ATF server side script test step. How can I do that please help me on that.
I am using the below code to calculate.
- TimeDiff();
- function getTimeDiff(){
- var startDate = current.u_start_date.getGlideObject();
- var endDate = current.u_end_date.getGlideObject();
- current.u_duration = gs.dateDiff(startDate.getDisplayValueInternal(),endDate.getDisplayValueInternal(),false);
- }
But I don't know how to use this code in server side script test step code.
Please help me out with this.
Thanks,
Deepa
- Labels:
-
Automated Test Framework
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2019 04:42 AM
Is there a button which trigger this?
use the same in the button.
You can call a script include from the button
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2019 04:53 AM
No, ATF (Automated Testing Framework) will automatically run these steps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2019 11:58 PM
Hi Deepa
You just need to replace the object 'current' with a GlideRecord object where you want to use it, e.g.:
function getTimeDiff(grTable){
var startDate = grTable.u_start_date.getGlideObject();
var endDate = grTable.u_end_date.getGlideObject();
return gs.dateDiff(startDate.getDisplayValueInternal(),endDate.getDisplayValueInternal(),false);
}
var grTable = new GlideRecord(<nameOfTable>);
grTable.get(<sysIDOfTheRecord>);
var duration = TimeDiff(grTable);
--
Best Regards
Ankush
P.S. Please mark helpful/correct as appropriate to help the fellow community member in identifying the relevant answers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2022 08:53 AM
This worked perfectly.
Thank you 🙂