Incident management - Obtaining the date and time when additional comments were registered
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 05:01 AM
This is about incident management.
After setting the assignment destination, I would like to obtain the date and time when the first additional comment was registered.
ServiceNow support gave me the following advice:
A script is required for the contents of the business rules. However, I have no experience with JavaScript. Can you give me some advice on the content of the script?
--Advice from support--
I think the concept should flow as follows.
1. Create a new date time field called "Temporary response date and time" in the incident
2. Create a business rule for the table as additional comments will be saved in sys_journal_field
The contents of the business rule are as follows:
1. Executed at insert time
2. In the case of an incident and a comment, check if there is another comment with the same Element ID in sys_journal_field, and if there is not, set a "temporary response date and time" for the incident.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 05:13 AM - edited 10-26-2023 05:20 AM
Hi @Shibayama ,
Write before insert business rule on incident table with below script.
(function executeRule(current, previous /*null when async*/ ) {
if (current.comments && current.u_date_and_time_comments == '') {
var gr = new GlideRecord('sys_journal_field');
gr.addQuery('element_id', current.sys_id);
gr.query();
if (gr.next()) {
current.u_date_and_time_comments = new GlideDateTime();
}
}
})(current, previous);
Please mark it as helpful and solution proposed if its serve you purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2023 11:46 PM
@Anand Kumar Pat
Thank you for answering.
It's been a great help.
In the script you gave me, the time when the second additional comment was registered is set to u_date_and_time_comments.
What I want to do is as follows.
Precondition: “Assigned to” value is set
Set the date and time when the first additional comment was registered after the value was set in "Assigned to" to u_date_and_time_comments.
I would appreciate your additional support.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 01:08 AM
Hi @Shibayama,
Try below script
(function executeRule(current, previous /*null when async*/) {
if (current.comments && current.u_date_and_time_comments == '' && current.assigned_to.changes()) {
var gr = new GlideRecord('sys_journal_field');
gr.addQuery('element_id', current.sys_id);
gr.query();
while (gr.next()) {
current.u_date_and_time_comments = new GlideDateTime();
break;
}
}
})(current, previous);
Please mark it as solution proposed if its serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 01:41 AM