fire an event with business rule

ammar_k
Tera Contributor

I want to delete a record under conditions ( in the business rules) 
how to pass the record id to the event ? 

thank you

6 REPLIES 6

Vengadeshgiri
Tera Contributor

Hi @ammar_k ,

 

Your description seems to be empty.Im not sure what you are asking is

But if you want to fire an event from BR use gs.eventQueue() method

Eg:gs.eventQueue("Event name","Object","Parm1","Parm2")

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

You can use the below script to do so

gs.eventQueue('event_name', gliderecord_object, 'string_parm1', 'string_param2', 'string_queue')

 

-Anurag

Community Alums
Not applicable

Hi @ammar_k 

 

If you want to pass current record sysid in event. You can write as written below.

gs.eventQueue('event_name', current, parmeter1, parmeter2);

 

Regards,

Krishna

ammar_k
Tera Contributor

I used this 

 

 

if (gs.nil(condition)) {
        gs.addInfoMessage('This record is empty and will be deleted in 30 minute if not updated.');

        // Fire the event to delete the empty problem after 30 minute
        var thirtyMinutesFromNow = new GlideDateTime();
        thirtyMinutesFromNow.addMinutes(30); 

        // Fire the event and pass the sys_id of the current record
        gs.eventQueueScheduled(
            'Event name',    // Event name
            current,                   // GlideRecord object (problem record)
            current.sys_id,            // Parm1: sys_id of the record
            null,                      // Parm2
            thirtyMinutesFromNow           // Scheduled time (1 minute from now)
        );
    }

})(current, previous);

 

 

 

then i used this script action : 

 

 

(function executeDeleteRecord(event) {
    var recordSysId = event.parm1;  // Get the sys_id of the record from the event
    var recordGR = new GlideRecord('record');

    if (recordGR.get(recordSysId)) {
        // Check if the record is still empty before deletion
        if (gs.nil(condition)) {
            gs.log('Deleting empty record: ' + recordGR.getUniqueValue());
            recordGR.deleteRecord();  // Delete the empty record
        }
    }
})(event);

 

 

 

this sysId of the record is always undefined ( in the event and the action script)