- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 11:14 PM
Issue :
an email notification is not getting triggered, it's trigger condition is set when a particular event triggers. so we need to trigger the event to trigger this notification
Requirement:
For testing purpose I want to trigger the event using script in background script if it is possible.
suppose event name is : my.event.name
param1: should be list of sys_ids in string format.
how can I trigger the event in the background script, using gs.eventQueue('my.event.name',......);
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 11:25 PM
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:
param1is a string containing a comma-separated list of sys_ids.split(',')is used to convert the string into an array of sys_ids.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.- Looping over the sys_ids ensures that the event is triggered for each sys_id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 11:20 PM
Hello,
Something like this needs to be done.
var eventName = 'event_name';
var sysIds = ['sys_id_1', 'sys_id_2', 'sys_id_3'];
var sysIdsString = sysIds.join(',');
gs.eventQueue(eventName, current(of you notif object), sysIdsString, null);
Let me know if that is what you were looking for,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 12:38 AM
Thanks for the reply @Omkar Mone , Previous replies solved my issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 11:25 PM
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:
param1is a string containing a comma-separated list of sys_ids.split(',')is used to convert the string into an array of sys_ids.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.- Looping over the sys_ids ensures that the event is triggered for each sys_id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 11:53 PM
Hi @PrashantLearnIT , will try and let you know.