Inquiry about Servicenow Report calculation field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-02-2025 12:51 PM - edited ā04-08-2025 09:53 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-02-2025 01:01 PM
Hello @ab_frostbite
Just create a custom field of string type and use below š script :
var gr = new GlideRecord('incident');
if (gr.get('<sys_id>')) { // Replace with an actual sys_id or query condition
var opened = new GlideDateTime(gr.opened_at);
var closed = new GlideDateTime(gr.closed_at);
var dur = GlideDateTime.subtract(closed, opened);
gs.info(dur.getDisplayValue
());
Populate that either using a scheduled job or business rule based on your conditions..
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-02-2025 01:05 PM
Hello @ab_frostbite ,
I assume you already have a report on Change Request and just need advice on how to add that calculated field.
In your Report creation screen ("Configure" step) please follow the steps shown in this screen shot:
The function to use is:
glidefunction:datediff(closed_at,end_date)
Now save the report, click on "Choose columns" and your new calculated field will be available to be added.
Result:
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-02-2025 01:09 PM
Hi @ab_frostbite ,
You create one custom field of type date and time. Then create a before BR on update on the table which have these fields. Condition Planned Start Date and Closed Date is not empty.
Use belo code
Current.custom_field_name = current.closed_date - current.planned_date
modify the field name as per the exact field name.
If my response helped, then please accept the solution and hit thumbs up.
Regards,
Rohit