How to create an event in run script?

SNnewbie2
Tera Expert

How do I create an event using an script in run script? I want to be able to create an event to create a notification for each person I want to send it to.

35 REPLIES 35

Priya R wrote:



You can write the logic in the script based on your needs.


.. or you can create a notification, rather than write a script.



Scripting should be avoided where possible, unless the provided methods are unsuitable.


My bad, I have gone with script action logic instead of email notification.


.. which is still a valid approach, but for emails a quicker route is the notifications.



(you'll be surprised at the number of times I've seen people script an email notification through Script Actions as an event response!)


SNnewbie2
Tera Expert

Thank you for all your responses! You guys are helpful!


I was able to create an event. I used the following line of code inside of my "run script" to create the event.



gs.eventQueue("arp_order_circuit", current , current.sys_id , current.sys_id);


Now I need to write code in my run script so that the owner group will receive the event. So I need to create an event for each separate recipient so that a notification gets created for each.



In my form I have a reference field in which the user will select the CI.


find_real_file.png


After he selects the CI. We will send a notification to the owner of the CI (recipients). For example the user select the CI called WAM, so in this case we will notify the following recipients (yellow marker).


find_real_file.png


SNnewbie2
Tera Expert

So I tried this but still not working....it creates an event but it never sends the notification


var groupID = current.impacted_ci_first.support_group.toString();


var userList = [];    


var mem = new GlideRecord("sys_user_grmember");    


mem.addQuery('group', groupID);


mem.query();    


gs.log(mem.getRowCount());


while (mem.next()) {    



              userList.push(mem.user.email.toString());    


}    



gs.eventQueue("catalog.opening.dns.notification", current, userList.join(','), '');