Child incident creation through Business rules

divvi_vamsi
Mega Expert

Hi,

I am pretty much new to this community and servicenow. I trying to create a child incident for an incident which was created through Scheduled Entity Generation.

Scenario:

Scheduled Entity Generation creates an incident where contact type is set 'Scheduled Generation'

An entity (incident) generated.

A Business Rule is generated to check whether the newly inserted incident's contact type is 'Scheduled Generation'. Below is the script:

When to Run: After Insert

Filter Conditions: Contact Type is Scheduled Generation

Advanced Script:

test();

function test(){

var inc = new GlideRecord("incident");

      inc.get('sys_id', current.sys_id);

//   if(inc.contact_type=='Scheduled Generation'){   //inc refers to current object, needed is a child of it...

  inc.parent_incident = current.sys_id;

  inc.category = current.category;

  inc.contact_type = 'Child inci';

      inc.insert();

      gs.log("Incident " + inc.number + " closed based on closure of incident " + current.number);

  }

}

I am not able to figure out, how to create a child incident....

Any suggestions would be helpful.

Thanks,

Divya

1 ACCEPTED SOLUTION

Hi Divya,



Thanks for the update. There was duplicate condition which I removed (I.e you defined condition filter and the other one in condition field)


The other was function template which you mentioned above.



Would you mind marking my response and close the thread as the issue is resolved now.


View solution in original post

19 REPLIES 19

Do you get that last log message in system logs?


I actually went through the logs and I found this message:



org.mozilla.javascript.EcmaError: "contact_type" is not defined.


Caused by error in Business Rule: 'test child incident' at line 1



==> 1: var inc = new GlideRecord("incident");


2: //inc.get('sys_id', current.sys_id);


3: inc.initialize();


4: inc.parent_incident = current.sys_id;


Divya,



    Can you paste the code, which you are using now.


Hi Abhinay,



Below is the code for your reference:



I have the following modified script:



function onAfter(current, previous) {


  var inc = new GlideRecord("incident");


  inc.initialize();


  inc.parent_incident = current.sys_id;


  inc.category = current.category;


  inc.contact_type = 'Child inci';


      inc.insert();


      gs.log("Incident " + inc.number + " closed based on closure of incident " + current.number);


}


Divya,



  In the line " inc.contact_type = 'Child inci';" does contact_type have a choice value "Child inci" (not the choice label)?