I need alert opened date should be populate on detection time filed in the incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I need alert opened date should be populate on detection time filed in the incident, Please suggest how to achieve this requirement and i have tried below After Business Rule on incident table but not works:
if (!current.u_detection_time && current.u_alert) {
var alertRec = new GlideRecord('u_alert');
if (alertRec.get(current.u_alert)) {
current.u_detection_time = alertRec.u_opened_at;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @ashok17 ,
The script is working and I verified on my end.
Make sure the business rule runs after insertion and verify the filed names.
Add log messages and check where it is failing.
(function executeRule(current, previous /* null when async */ ) {
// Get the reference to the related Incident record from the Alert
gs.log("Sync Detection time BR Executed.","syncBR");
var incidentSysID = current.u_task; // reference field on Alert table
gs.log("Incident sysID:"+incidentSysID,"syncBR");
if (incidentSysID) {
var incGr = new GlideRecord('incident');
if (incGr.get(incidentSysID)) {
// Set Detection Time on Incident
incGr.u_detection_time = current.u_opened_at; // alert's opened date
incGr.update();
gs.log("Detection Time updated for incident " + incGr.number + " with " + current.u_opened_at,"syncBR");
} else {
gs.log("Incident not found for sys_id: " + incidentSysID,"syncBR");
}
}
})(current, previous);
try with new records.
1.Create a incident and save the record.
2.Then create a alert record and check.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Rakesh_M ,
I have tried same script in After Business Rule but did not work for my side, please refer below screenshots and suggest if any wrong on script side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @ashok17 ,
Can you share the logs with source=syncBR.
also share when to run condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Below is the condition have given in Business Rule and could you please confirm the Business Rule have selected incident is it correct right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
hi @ashok17 ,
Please update the table name to the Alert table.
The current Business Rule works when the Incident is created first, and then the Alert is created — in this case, the Incident gets updated.
If your use case is different (for example, creating the Alert first and then the Incident), the script will need to be adjusted.
Could you please confirm your use case?