- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 01:33 AM
Hi Developers,
I need the Duration field on sc_task table to display the time difference between Created on and closed fields. I have tried below code in before Business Rule with condition when closed changes.
current.calendar_duration = GlideDateTime.subtract(new GlideDateTime(current.getValue("sys_created_on")), new GlideDateTime(current.getValue("closed_at")));
current.update();
Also, i tried with Client script and Script include. When this field is on form, it is displayed with duration and when hidden from form, no value is record in duration field.
Note: I need duration field to be recorded with time when the task is closed though it is not displayed on form view.
Could someone help me in solving this issue?
Thanks in advance.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 01:15 AM
It worked out for me with same code.. only modification in this is i have changed Before Business to after BR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 02:12 AM
Instead of using .subtract, you can use dateDiff function in servicenow to calculate difference between duration fields.
https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GS-dateDiff_S_S_B
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 02:50 AM
thanks for you response Prasanna, it didn't worked out in my case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 03:03 AM
Hi,
You might find this post helpful in your case. The similar requirement was achieved here:
https://community.servicenow.com/community?id=community_question&sys_id=d2c3c7a5dbd8dbc01dcaf3231f96190a
I hope this helps.Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 01:15 AM
It worked out for me with same code.. only modification in this is i have changed Before Business to after BR.