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

Community Alums
Not applicable

Hey there,

 

You should be able to create a Business Rule where the conditions are "Work Notes" <changes>. Then in the script, you will need the following:

 

var notes = current.work_notes.getJournalEntry(-1);

if(notes.indexOf("MetricName: 'testing';" > -1 && notes.indexOf("PodName: 'testing1';" > -1) {
   // make the association to your parent incident here
}

 

Hope that helps!

 

~Nick

Narsing1
Mega Sage

You can think of using GlideSPScriptable.getStream function.

Here is the Article for your reference on how to use

 

Thanks,

Narsing

Tai Vu
Kilo Patron
Kilo Patron

Hi @Ajay Singh2 

You can use script to verify the work notes of the current record by using methods such as: indexOf, includes, contains, etc.

 

Cheers,

Tai Vu

Ajay Singh2
Tera Contributor

Hi Timi I have written below codes but not working as Incident is created from sending alerts.

(function executeRule(current, previous /*null when async*/) {

// Script for Location field
    //current.work_notes.indexof('MetricName') != -1 && current.work_notes.indexof('PodName') != -1;

    var workNotes = current.work_note.getJournalEntry(-1);
    //var metricNameMatch = workNotes.match(/Metricname:\s*(.*)/);
    //var podNameMatch = workNotes.match(/PodName:\s*(.*)/);

    //var metricName = metricNameMatch ? metricNameMatch[1].trim() : '';
    //var podName = podNameMatch ? podNameMatch[1].trim() : '';

    //check if worknotes contains metricname

    if (notes.indexOf("MetricName : 'current.metricName';"> -1) && notes.indexOf("PodName : 'current.podName';"> -1)) {
    var gr = new GlideRecord('incident');
        gr.work_notes = "child incident for " + metricName + "on" + podName;
    //gr.addQuery('work_notes', current.metricName);
    //gr.addQuery('work_notes', current.podName);
    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

    }

    else {
        current.update();
    }
    }

})(current, previous);
 
Thank You!!