
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 05:55 PM
I have a portal page that can show system outages, on that page our users can subscribe to a service so that if there is any sort of outage/degradation they will receive an email notification about what is happening.
This has always been a manual process to add users to a service and have them go to unsubscribe if they decided they didn't want to receive notifications for any particular service.
The page looks like this:
What it looks like on the Service record in the ITSM module is:
Those people who are listed on the service under "Users" are the subscribed users and they can be manually added via the "edit" option and chosen from the list.
What I want to do is to have new staff created "today" auto added to the "user" part of each of the services we have on our portal page (which is not every service) and have them be able to go and unsubscribe later if they wish, but by default all new users get auto subscribed to each of these services.
I'm think a business rule, but really don't know how to create one for this, is someone able to show me how it should be setup?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 06:19 PM - edited 03-01-2023 06:21 PM
Ok, good, glad it's going. To scale this, yes, you could add a comma separated list to a system property that you create of all the services that they should get auto added to. System property should be string type and have a value like sys_id1,sys_id2,sys_id3
Then in your script, you can call it in like:
var services = gs.getProperty('name_of_property');
var array = services.toString().split(',');
for (var i = 0; i < array.length; i++) {
var gr = new GlideRecord('m2m_sp_status_subscription');
gr.initialize();
gr.cmdb_ci_service = array[i];
gr.sys_user = current.sys_id;
gr.insert();
}
So that should iterate through the common separated list and add them to each service. This method avoids any customization, but another way could be that you add a checkbox field to the service form and call it: "Auto-Subscribe" or something like that and then check that box on those services, then use a GlideRecord query to query those services for that checkbox to be true and while loop through them using a script similar to the above except the array[i] would be the service sys_id, such as gr.sys_id if you used gr for your GlideRecord query (see my original reply with the link to the documentation).
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 07:22 AM
Hi,
Sorry, I'm getting a bit lost as to what you're trying to do. I thought this entire discussion was around a brand new user who is created and is auto-added as a "subscriber" to specific services that you identity (such as email, for 1 example). So my approach and script is related to using a business rule, which executes on the insert/creation of a new record on the sys_user table that will take them and add them to the "Users" list for that particular service.
I've provided code initially and then replied with additional information that should help finish it. I'm not sure where the widget has anything to do with this and why data.toSubscribe[j] was added to the business rule script. I mentioned in my previous reply to use the sys_id of the service record (again, such as email). So you'd go to the services list, right click on the Email service, choose "Copy Sys ID" and then use that on the addQuery line related to the cmdb_ci_service. If you simply try with just the one service, for now, you should see that when you create a new user record, they get added to that service.
Please review my replies, thank you.
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 05:01 PM
Obviously, I really did confuse you @Allen Andreas , very sorry.
The widget came in just because there was already a function in there that a user could click on and it would add them to all services to receive notifications and I thought maybe that script might work for a new user and add them to all services.
I've gone back to what you suggested at the very start and added a business rule on the sys_user table that runs when a brand new user is created.
The sys ID of the email service is: 2627b30b642b530056fe64447b35348b
The script is:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord('cmdb_ci_service');
gr.initialize();
gr.user = current.sys_id;
gr.insert('2627b30b642b530056fe64447b35348b');
})(current, previous);
Still not working however

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 05:55 PM
Hi,
It's all good, haha. Just trying to troubleshoot this and then when I thought I understood, something else pops up and I'm like...ok...so...wait...what? lol..
Anyways, please try this and hopefully it makes sense to you after you see it and all that:
var gr = new GlideRecord('m2m_sp_status_subscription');
gr.initialize();
gr.cmdb_ci_service = '2627b30b642b530056fe64447b35348b'; //should be the sys_id of the cmdb_ci_service record involved - such as Email
gr.sys_user = current.sys_id;
gr.insert();
If you look back at my 2nd reply, way up top there, you'll see where I call out the table involved, so you'll see that in my script here. I call out the 2 fields involved and give their names, you'll see that in my script here as well. This should hopefully work for you.
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 06:10 PM
Thanks @Allen Andreas that certainly works for the new user adding to the email service 🙂
So my question is now how to I add them to all the services that I need to added to?
Separate business rules for each service? (I hope not lol)
Repeat the code over and over in the one business rule with each sys id for each service in them?
Something way smarter?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 06:19 PM - edited 03-01-2023 06:21 PM
Ok, good, glad it's going. To scale this, yes, you could add a comma separated list to a system property that you create of all the services that they should get auto added to. System property should be string type and have a value like sys_id1,sys_id2,sys_id3
Then in your script, you can call it in like:
var services = gs.getProperty('name_of_property');
var array = services.toString().split(',');
for (var i = 0; i < array.length; i++) {
var gr = new GlideRecord('m2m_sp_status_subscription');
gr.initialize();
gr.cmdb_ci_service = array[i];
gr.sys_user = current.sys_id;
gr.insert();
}
So that should iterate through the common separated list and add them to each service. This method avoids any customization, but another way could be that you add a checkbox field to the service form and call it: "Auto-Subscribe" or something like that and then check that box on those services, then use a GlideRecord query to query those services for that checkbox to be true and while loop through them using a script similar to the above except the array[i] would be the service sys_id, such as gr.sys_id if you used gr for your GlideRecord query (see my original reply with the link to the documentation).
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!