- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2016 12:10 PM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2016 09:34 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2016 09:15 PM
Hi Divya,
I got in to your instance and resolved the issue.
Basically there was issue with function template and condition field. Can you please confirm if this is working fine now?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2016 09:30 PM
Hi Pradeep,
It is working totally fine. Thanks a lot, but can you be more elaborate about the issue that you resolved?
Initially I tried executing with (function executeRule), but it didn't work for me...
Thanks,
Divya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2016 09:34 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2016 09:41 PM
Hi Pradeep,
Q1) Is that duplicate condition a matter of redundancy or is it one of the reason for the current issue?
Q2) Business Rule scripts work only within that template? because few scripts work even without any function definitions too...
Thanks
Divya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2016 09:49 PM
Final working solution:
When to Run: After Insert
Filter Condition: Contact Type is Scheduled Generation
Advanced Script:
(function executeRule(current, previous /*null when async*/) {
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.addInfoMessage("Incident " + inc.number + " closed based on closure of incident " + current.number);
})(current, previous);
pradeepksharma thanks for the support