Select to view content in your preferred language

Find view's source HFL when you don't own it?

992
6
Jump to solution
09-16-2024 11:08 AM
RandyMcGregor_BMcD
Frequent Contributor

I need to programmatically change ownership of a view. This requires that I first find the service with which the view is associated and change the ownership of that service. I had good luck with this until I tried it on content I don't own:

This code produces an empty list. 'check_item' is a feature service view.

 

source_hfl_list = check_item.related_items(rel_type="Service2Data",direction="reverse")
print(str(source_hfl_list))

 

I do have admin privileges. Is there any way to get this information that doesn't require me to own the items? I can change ownership in the service itself 'manually' but scaring it up is a bit of a hassle and I'd like to do it from a notebook that accesses the view only.

Thank you,

Randy McGregor

0 Kudos
1 Solution

Accepted Solutions
ChristopherCounsell
MVP Regular Contributor

You can update this script to return all users items in the search. Add for loop on fly and if logic for layerViews or sourceServiceName presence, to return view or source and associated views/source for the item.

View solution in original post

0 Kudos
6 Replies
ChristopherCounsell
MVP Regular Contributor

To run this with .related_items you need to be the item owner or the default administrator (not a custom role with admin privileges).

You can achieve this by viewing the layer definition admin properties.

from arcgis import GIS
from arcgis.features import FeatureLayerCollection

gis = GIS("Home")

source_item = gis.content.search("xxxxxxxxxxxxxxxxxxxxxxxx")[0]
flc = FeatureLayerCollection.fromitem(source_item)
print(flc.layers[0].manager.properties.adminLayerInfo.viewLayerDefinition.sourceServiceName)

 

ChristopherCounsell
MVP Regular Contributor

You can update this script to return all users items in the search. Add for loop on fly and if logic for layerViews or sourceServiceName presence, to return view or source and associated views/source for the item.

0 Kudos
RandyMcGregor_BMcD
Frequent Contributor

I did a slightly different thing, but used this concept. Our naming conventions are very standardized so I am able to remove the word "_View" from the item title. 99% of the time this is the hosted feature layer name. Then I can list layers with this name (which includes views made from it, somewhat confusingly...) then check for typeKeyword does not include 'View Service.' That gives me the HFL.

Thank you,

Randy McGregor 

0 Kudos
Clubdebambos
MVP Regular Contributor

Hi @RandyMcGregor_BMcD,

I had the same issue, I was getting an empty list [] with "Service2Data", but worked with "Service2Service", returned a list with one entry, the Item object representing the the source Feature Service.

from arcgis.gis import GIS

## access ArcGIS Online
agol = GIS("home")

## get the view as an Item object
view_item = agol.content.get("VIEW_ITEM_ID")

## get the source item from the related_items()
source_item = view_item.related_items(
    rel_type = "Service2Service",
    direction = "reverse"
)[0] # get the item object from the list

print(source_item)
~ learn.finaldraftmapping.com
RandyMcGregor_BMcD
Frequent Contributor

I tried both service2service and service2data. I think the ownership issue Chris mentioned is the culprit. I have a custom role with admin privileges.

ChristopherCounsell
MVP Regular Contributor

https://developers.arcgis.com/rest/users-groups-and-items/related-items/

Only default administrators and item owners have access to related items.

This applies to the function and relationship type parameters.

I've tested the earlier script with a custom admin role and it works fine.