PrashantLearnIT
Tera Sage

Hi @Community Alums 

 

To trigger an event in the background script using gs.eventQueue, you can pass the required parameters to the function. Here's an example of how you could do it:

// sys_id list in string format (assuming it's a comma-separated list of sys_ids)
var param1 = "sys_id1,sys_id2,sys_id3";

// Converting the string into an array of sys_ids
var sysIdArray = param1.split(',');

// Assuming we are triggering the event for each sys_id in the list
for (var i = 0; i < sysIdArray.length; i++) {
var sysId = sysIdArray[i];

// You need to pass a GlideRecord or any object as the second parameter.
// If it's for a specific table, you can retrieve the record.
var gr = new GlideRecord('your_table_name'); // Replace 'your_table_name' with the actual table
if (gr.get(sysId)) {
gs.eventQueue('my.event.name', gr, param1);
gs.info('Event triggered for sys_id: ' + sysId);
}
}

Explanation:

  1. param1 is a string containing a comma-separated list of sys_ids.
  2. split(',') is used to convert the string into an array of sys_ids.
  3. gs.eventQueue('my.event.name', gr, param1); is where the event is triggered. The first parameter is the event name, the second is the GlideRecord, and additional parameters can be passed afterward.
  4. Looping over the sys_ids ensures that the event is triggered for each sys_id.

 

 

********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

View solution in original post