How to update the Existing record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2017 12:25 AM
Hi ,
i have created the business rule on event table so that it will create incidents , if similar events occur it must go and update the same incident , i had written script for creating incidents i am unable to do it update , any one please help me on this
here is the script which i wrote for creation
if(createIncident == true)
{
var inc = new GlideRecord("incident");
inc.initialize();
inc.contact_type = 'Monitoring';
inc.short_description = current.short_description;
inc.description = current.description;
inc.cmdb_ci = current.cmdb_ci;
inc.caller = 'Event Management';
if (current.u_severity == 'critical' || current.u_severity == 'major')
{inc.urgency = '1'; // high
} else {
inc.urgency = '2'; // medium
}
if (current.u_severity == 'critical')
{inc.impact = '1'; // high
} else {
inc.impact = '2'; // medium
}
var sysID = inc.insert();
current.u_incident = sysID;
current.u_event_logs += 'New Incident created-->'+current.u_incident.number+ '\n';
var mySysID = current.update();
Thanks in advance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2017 12:34 AM
is this after business rule? if yes then i would recommend you to use setWorkflow(false) before the update.
Please check the below thread. same way you can do it for event.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2017 12:54 AM
Hi sasidhar,
AS i can see yourcode ius good enogh to create incident to for updating existing event we need to change the code as below:-
if(createIncident == true)
{
var inc = new GlideRecord("incident");
inc.addQuery("short_description",current.short_description);//please make it sure that your sgort description is same as your event name so as to make something unique to identify the event
inc.query();
if(inc.next())
{
inc.contact_type = 'Monitoring';
inc.short_description = current.short_description;
inc.description = current.description;
inc.cmdb_ci = current.cmdb_ci;
inc.caller = 'Event Management';
if (current.u_severity == 'critical' || current.u_severity == 'major')
{inc.urgency = '1'; // high
} else {
inc.urgency = '2'; // medium
}
if (current.u_severity == 'critical')
{inc.impact = '1'; // high
} else {
inc.impact = '2'; // medium
inc.update();//this will update the existing incident which was created by you event.
}
else
{
inc.initialize();
inc.contact_type = 'Monitoring';
inc.short_description = current.short_description;
inc.description = current.description;
inc.cmdb_ci = current.cmdb_ci;
inc.caller = 'Event Management';
if (current.u_severity == 'critical' || current.u_severity == 'major')
{inc.urgency = '1'; // high
} else {
inc.urgency = '2'; // medium
}
if (current.u_severity == 'critical')
{inc.impact = '1'; // high
} else {
inc.impact = '2'; // medium
}
inc.insert();
}
In the above code if short descrition is found then existing incident will be updated other wise system will enter else condition to create a new record.
Hope this will sort your issue.
PLZ mark this correct if it resolved your issue or feel free to ask if u still have any queries.
Regards,
Shubh