I need alert opened date should be populate on detection time filed in the incident

ashok17
Tera Contributor

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;
}
}

22 REPLIES 22

Rakesh_M
Kilo Sage

hi @ashok17 ,

Can you share the exact table names and field names involved, and clarify which field value should be populated from which field?

ashok17
Tera Contributor

Thanks for response, Please find the attached screenshots for reference.

When ever incident have alert in then alert opened date should be populated in the Detection time field in the incident.

Hi @ashok17 ,

Your requirement is to populate the Detection Time field on the Incident table using the Opened field from the Alert table.

To achieve this, create a Business Rule that runs after an Alert record is inserted and updates the corresponding Incident record’s Detection Time field.

Steps:

  • Create a new Business Rule

  • Table: Alert table

  • Advanced: Checked

When to run:

  • When: After

  • Insert: Checked

Then, in the script, update the related Incident record with the Alert’s Opened value.

(function executeRule(current, previous /* null when async */) {

    // Get the reference to the related Incident record from the Alert
    // Replace 'u_incident' with the actual reference field on your Alert table
    var incidentSysID = current.u_incident;

    // Check if the Alert is linked to an Incident
    if (incidentSysID) {

        // Initialize GlideRecord for Incident table
        var incGr = new GlideRecord('incident');

        // Fetch the related Incident record using sys_id
        if (incGr.get(incidentSysID)) {

            // Set Detection Time (or Alert Time) on Incident
            // Replace 'u_alert_time' with the correct field name on Incident
            // current.sys_created_on represents the Alert "Opened" time
            incGr.u_alert_time = current.sys_created_on;

            // Update the Incident record with the new value
            incGr.update();
        }
    }

})(current, previous);


Make sure to replace the placeholder field names in the script with your actual field names



ashok17
Tera Contributor

Tried below script but did not works

(function executeRule(current, previous /* null when async */ ) {
// Get the reference to the related Incident record from the Alert
var incidentSysID = current.u_task; // reference field on Alert table

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);
} else {
gs.log("Incident not found for sys_id: " + incidentSysID);
}
}
})(current, previous);