how to send notification of a problem to all child incident linked to parent incident?

jack33
Tera Expert

When problem created from incident the notifications about problem progress will send to first reported by incident's caller.I want to send these notification to all child incident linked with first reported incident.

var first_reported_by_task = current.first_reported_by_task.getDisplayValue();
var gr = new GlideRecord('incident');
gr.addQuery('problem_id',current.sys_id);
gr.query();
while(gr.next())
{
if(gr.number==first_reported_by_task){
var callerid =gr.getDisplayValue('caller_id.email');
var openby=gr.getDisplayValue('opened_by.email');
gs.eventQueue('Fired.caller.opendby.from.incident',current,callerid,openby);
}
}

 

How can I modify this.

Please help.

 

1 ACCEPTED SOLUTION

Monali Patil
Kilo Guru

Hi jack,

Try this code.write business rule on problem table

var problemid =current.sys_id;
var au =new ArrayUtil();
var list =[];

var gr =new GlideRecord('incident');
var q1 =gr.addQuery('problem_id',current.getValue("sys_id"));
q1.addOrCondition('parent_incident.problem_id',current.getValue("sys_id"));
gr.query();
while (gr.next()) {
    list.push(gr.getDisplayValue('caller_id.email'));
    list.push(gr.getDisplayValue('opened_by.email'));

}
var shortList = au.unique(list);

for (var i =0; i<shortList.length;i++) {
    gs.eventQueue('event name',current,shortList[i],problemid);
}

 

Email script:

var inc =new GlideRecord('incident');
var q2 =inc.addQuery('problem_id',event.parm2);
q2.addOrCondition('parent_incident.problem_id',event.parm2);
var q1 =inc.addQuery('caller_id.email',event.parm1);
q1.addOrCondition('opened_by.email',event.parm1);
inc.query();

while(inc.next()) {
    var number,state;
    if(inc.problem_id==event.parm2) {
        number=inc.getDisplayValue('number');
        state=inc.getDisplayValue('state');
    } else {
        number=inc.getDisplayValue('parent_incident');
        state=inc.getDisplayValue('parent_incident.state');
    }
    template.print('Incident Number: ');
    template.print(number);
    template.print('<br>');
    template.print('Incident State: ');
    template.print(state);
    template.print('<br>');
}

And call this email script in notification

Regards,

Monali Patil

View solution in original post

5 REPLIES 5

DrewW
Mega Sage
Mega Sage

Change this line

gr.addQuery('problem_id',current.sys_id);

to

gr.addQuery('problem_id',current.getValue("sys_id")).addOrCondition('parent', current.getValue("first_reported_by_task"));

I believe that is what you are looking for.

Hi drew,

Thanks for feedback,its working for me.

I also want to send notification to child incident whose parent linked in related list(incident) of problem.Can you please help me in this? 

How you go about that is going to depend on the related list and how it is defined.  The breadcrumb at the top of the related list should give you a hint.  Like if it says something like "Problem = PRBXXXXXXX" and its a list of incidents then query the incident table where the problem field is equal to the current record.  If there is no breadcrumb then you need to find the list definition and figure it out from there.

find_real_file.png

DirkRedeker
Mega Sage

Hi

I just created a small script for you, which should show you how to

a) collect the "caller ID" and "opened by" from your "first_reported_incident", AND

b) collect ALL the "caller IDs" and "opened by" email addresses from ALL child Incidents of your "first_reported_incinet".

The script below, which you can run in Scripts Background.

YOu just need to adjust a bit to your implementation.

 

var first_reported_by_task = 'INC0000001';

var grParent = new GlideRecord('incident');
grParent.addQuery('number', first_reported_by_task);
grParent.query()

var arrTo = [];

if (grParent.next()) {
    var callerid = grParent.caller_id.email;
//    var callerid = grParent.getDisplayValue('caller_id.email');
//    var callerid = grParent.getElement('caller_id.email');
    var openby   = grParent.opened_by.email;

gs.info(callerid);

    arrTo.push(callerid);
    arrTo.push(openby);

    // Read all child Incidents of this incident as well
    var grChild = new GlideRecord('incident');
    grChild.addQuery('parent', grParent.getValue('sys_id'));
    grChild.query();

    while(grChild.next()) {
        callerid = grChild.caller_id.email;
        openby   = grChild.opened_by.email;

        arrTo.push(callerid);
        arrTo.push(openby);
    }
}

gs.info(arrTo);

// Push Array with Recipients to the Event
gs.eventQueue('Fired.caller.opendby.from.incident',current,arrTo);


 

Let me know if that answers your question and mark my answer as correct and helpful.

Have fun & BR

Dirk