how to match the Worknotes values dynamically using Business rule

Ajay Singh2
Tera Contributor

Can anyone explain how to match the incident work notes values in Business rule to create a Parent/Child relationship.

 

MetricName: 'testing';

PodName: 'testing1';

 

Based on above these two values from work notes we need to create a parent/child relationship in Incident table.

 

Thank You!!

10 REPLIES 10

Hi @Ajay Singh2 

Can you help to share details of requirement for better understanding about what we are trying to achieve?

 

Cheers,

Tai Vu

Hi Timi

 

I am getting MetricName and PodName in alerts in Worknotes. See attached file you will get MetricName and PodName based on these two names values I need to set Parent/Child relationship.

 

Thank You!!

 

Hi @Ajay Singh2 

It looks like you're trying to query other Incidents with the same MetricName and PodName under work notes to link them to a specific parent record.

The current approach seems a bit unstructured, to me, since you're trying to retrieve data specifically from work notes. A better approach might be to leverage the Correlation ID field, which typically stores a unique identifier from a third-party system. By using this attribute, you can easily identify and associate parent and child records without relying on work notes.

 

If you still wanna approach with work notes, the work notes query should be like below.

gr.addQuery('work_notes', 'CONTAINS', <MetricName>); //the value of metric name attribute

 

So basically, the steps should be:

1. Parse the JSON object from the Incident work notes. If the alert make a post with payload only to your work notes, you can consider below script to achieve this.

2. Get value of Metric Name and Pod Name.

3. Do query with work notes contains the Metric Name and Pod Name

4. Update to link to the parent incident

Sample

var grJournal = new GlideRecord('sys_journal_field');
grJournal.addQuery('name', 'incident');
grJournal.addQuery('element', 'work_notes');
grJournal.addQuery('element_id', current.getUniqueValue());
grJournal.orderByDesc('sys_created_on');
grJournal.setLimit(1);
if(grJournal.next()){
	var payload = grJournal.getValue('value');
}

payload = JSON.parse(payload);
var podName = payload.PodName;
var metricName = payload.Trigger.MetricName;

var gr = new GlideRecord('incident');
//gr.addQuery('sys_id', '!=', curent.getUniqueValue()); //filter out the current record
gr.addQuery('work_notes', 'CONTAINS', podName);
gr.addQuery('work_notes', 'CONTAINS', metricName);
gr.addEncodedQuery('active=true^state!=6');
gr.orderBy('sys_created_on');
gr.setLimit(1);
gr.query();
if (gr.next()) {
	current.parent_incident = gr.sys_id; // updating child record
	current.update();
}

 

Cheers,

Tai Vu

Hi @Tai Vu 

While using above code when i tried to create a new incident it's not working.

Can you explain or provide some guidance why it's not working.

 

Thank You!!

Hi @Ajay Singh2 

Have you tried any debug to see what was wrong during execution? Can you share a screenshot of the incident work notes and the text of the JSON payload? 

 

Cheers,

Tai Vu