Incident created from alert and getting value in work_notes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 11:56 PM
Hi All,
Incident is created from integration and based on that in work_notes getting MetricName and PodName values. So based on these two I have written Business Rule to make Parent-Child relationship and for this I used Journal table and everything is working as expected Parent-Child relation is created but issue is Child Incident can not identify the Closed and Active incident from journal table so it always make the last incident created as Parent which is long ago closed but we need the active incident to be Parent. Can any one any idea how to achieve this below code I used to make Parent-Child from Journal table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2024 02:59 AM
Hello Ajay,
Can you specify what is not working? As I have only added the last part differently where it querys all the incidents matching the work notes text. Can you put some logs around and let me know? As I can see the background script working for me -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2024 06:18 AM - edited 10-11-2024 06:21 AM
In when to run condition i used below condition see screenshot.
While creating Incident getting same incident as parent.
These errors are also visible.
Creating Incident from Rest Api Explorer
While getting alert to create Incident form MetricName and PodName values are coming like this see below screenshot.
Thank You!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2024 04:55 PM
Hello Ajay,
I see, I tried this version in my PDI and its returning the values as expected. Can you give it a try?
(function executeRule(current, previous /*null when async*/) {
var grJournal = new GlideRecord('sys_journal_field');
grJournal.addQuery('element_id', current.sys_id);
grJournal.addEncodedQuery('nameSTARTSWITHincident^element=work_notes^valueLIKEPodName^valueLIKEMetricName');
grJournal.orderByDesc('sys_created_on');
grJournal.query();
var payload = '';
if (grJournal.next()) {
payload = grJournal.getValue('value');
}
var podNameRegex = /"PodName"\s*:\s*"([^"]+)"/;
var metricNameRegex = /"MetricName"\s*:\s*"([^"]+)"/;
var podNameMatch = payload.match(podNameRegex);
var metricNameMatch = payload.match(metricNameRegex);
var podName = podNameMatch ? podNameMatch[1] : '';
var metricName = metricNameMatch ? metricNameMatch[1] : '';
var grJournalsec = new GlideRecord('sys_journal_field');
grJournalsec.addEncodedQuery('valueLIKE' + podName + '^valueLIKE' + metricName);
grJournalsec.addEncodedQuery('nameSTARTSWITHincident^element=work_notes^element_id!=' + current.sys_id);
grJournalsec.orderByDesc('sys_created_on');
grJournalsec.setLimit(1);
grJournalsec.query();
var parentIncidentId;
if (grJournalsec.next()) {
parentIncidentId = grJournalsec.getValue('element_id');
}
gs.info("Printing the parent sysid - " +parentIncidentId)
if (parentIncidentId) {
current.parent_incident = parentIncidentId;
current.update(); //see if you want to remove this as BR is on before insert/update as I think its not needed.
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2024 10:27 PM
@Omkar Mone Not its still not working. Now only Incident is created one bye one no relation.
Thank You!!
