Subscribed by Location in case of a parent location

marcguegueniat
Kilo Sage

Hello,

 

I have 2 locations:

- "Site1" (Location Type=Site) with parent location "Rio de Janeiro" (Location Type=City)

- "Site2" (Location Type=Site) with parent location "Rio de Janeiro" (Location Type=City)

 

I also have 2 users:

- user A with Location = "Site1"

- user B with Location = "Site2"

 

I have created a catalog article that is is linked to a service offering ("Available For Subscribers" relation)

If I make the service offering "Subscribed by Location Site1", it works:

- user A see the catalog article

- user B does not

 

But if I make the service offering "Subscribed by Location Rio de Janeiro":

- none of the users can see it

 

I would have expected child locations to be taken into account so that both users would see the catalog item.

 

Can anyone confirm that this is the expected behavior?

I could not fin any documentation reference to precisely tell whether it is expected or not.

 

Regards,

1 ACCEPTED SOLUTION

CMDB Whisperer
Mega Sage
Mega Sage

Hi All,

 

As @Barry Kant pointed out (thanks again!) I have confirmed that it is indeed the ServiceSubscriptionUtils script, not the SPMSubscriptionUtils script, that is being executed when evaluating which Catalog Items are visible to users based on the Offering Subscriptions.  Furthermore, I have validated that you can indeed modify this script to that it will include all parent locations of the user's Location, which avoids the need to individually subscribe every child location at the Offering level.

 

Here is the code change needed to subscribe Locations recursively:

CMDBWhisperer_0-1685751084618.png

 

Here is the modified _addLocation function:

   _addLocation: function(answer, location_id) {
        var gr = new GlideRecord(this.constants.SERVICE_SUBSCRIBE_LOCATION);

		var qry = gr.addQuery('cmn_location', location_id);
		
		//FIX for recursive subscription: add parent locations
		var grLoc = new GlideRecord('cmn_location');
		while (!gs.nil(location_id)) {
			if (grLoc.get(location_id)) {
				location_id = grLoc.getValue('parent');
				if (!gs.nil(location_id)) {
					qry.addOrCondition('cmn_location', location_id);
				}
			}
		}
		
        this._query(gr, answer);
    },

 

IMPORTANT:  When testing this change, clear your server and browser cache before testing the results or else you may not see the change occur!

 

You can follow the same approach to recursively subscribe to Companies, Departments, and Groups as well.

@marcguegueniat (and others) please try this out and mark this as a Solution if this works for you.  And if it doesn't, let me know because I'd love to see this through to resolution!


The opinions expressed here are the opinions of the author, and are not endorsed by ServiceNow or any other employer, company, or entity.

View solution in original post

13 REPLIES 13

Stig Brandt
Tera Guru

Subscribe by on service offerings, doesn't unfortunately support the parent record, you need to build a rule to add / remove all children if you subscribe by a parent record 😞

CMDB Whisperer
Mega Sage
Mega Sage

My findings during testing were the same, that child locations are not included in the subscribed users.  One thing I will note here is that during testing I also found that I had to flush the server cache with cache.do every time I made a change to the subscriptions, which led me astray in my findings several times if I forgot to do this.

 

The script include for this does not support including hierarchical Companies, Departments, or Groups.  You would need to either modify the OOB script include SPMSubscriptionUtils to traverse the hierarchy and include all users recursively, or build a business rule to cascade this down to automatically add child objects to the subscriptions.  In my opinion the former is a better solution, since the latter solution would mean that your subscriptions would need to be removed and recreated whenever you have an organizational change. [UPDATE:  See the later posts below; this script is used not for determining catalog item visibility for the logged on user but for other purposes.]

 

However, when you actually look at the code, it appears that Locations are recursive.  For some reason it does not appear to be working that way, so there may be a bug in the OOB script include that hasn't been uncovered yet.  Up to now I had assumed the same issue existed for subscribed Locations as the issues that exist for the other subscriptions, but as you can see below, this appears to have been designed to include recursive locations.

 

CMDBWhisperer_0-1685028956213.png


The opinions expressed here are the opinions of the author, and are not endorsed by ServiceNow or any other employer, company, or entity.

Hello and thanks for your answer,

 

I've looked at my customer's instance and Script include SPMSubscriptionUtils does not exist. I can find it on my PDI where I have installed additional SPM related plugins. So actually SPMSubscriptionUtils probably comes from an additional plugin.

So the real code that determine visiblity is probably not this script but somewhere else. That would explain why this code does not seem to be working.

On the other hand your finding may reveal that Subscribed by Locations are indeed meant to be recursive and that would be a bug.

I will raise a Now Support ticket to clarify this.

 

Regards,

hi all,

it is correct. It is not the only logic to check subscriptions. In DPM there is a logic (scheduled once a day) that calculated the total number of Subscribers. Keep in mind that if you change 1 logic that it gets out of sync with the other logic. 
Also it is not easy to extend the logic this way (I once added subscribed by Business Unit as that company had everything managed on that level). --> BTW, Departments also do not check child departments.