FeatureSetByPortalItem - Picking an Enterprise Portal?

666
5
06-07-2023 05:08 PM
Labels (1)
ghaskett_aaic
New Contributor II

Hello,

I am trying to build a new data expression in a serial chart within my ArcGIS Dashboard app using FeatureSetByPortalItem().

I can create one connecting to my AGOL account, however I don't seem to be able to create one connecting to my local Enterprise Portal account.  When I try I get the following error message: 

Execution Error:Item does not exist or is inaccessible.

From what I can read via: https://developers.arcgis.com/arcade/guide/types/#portal

I should be able to connect to a service via its service ID.  The service exists, but I am not able to connect to it.  Right now the service is shared with a Beta Testing group within our Portal.

Is there a chance my share settings are blocking it?  I am an admin and member of said group.  I have tried both the default 'www.arcgis.com' and the URL for my Enterprise Portal.  

Any ideas?  Thanks

 

 

 

var p = Portal('https://www.arcgis.com');

var features = FeatureSetByPortalItem(
  p,
  'xxxxxxxxxxxx',
  0,
  ['*'],
  false
);
Count(features);

 

 

 

 

 

0 Kudos
5 Replies
jcarlson
MVP Esteemed Contributor

The URL must be the portal's URL, i.e., https://maps.co.kendall.il.us/portal would be mine.

If you're trying to access a service that is not shared publicly, it should prompt you to log in. Where are you running the expression, AGOL or your portal? Is the layer shared?

- Josh Carlson
Kendall County GIS
ghaskett_aaic
New Contributor II

Thanks.

I am running the expression via an ArcGIS Dashboard on our Enterprise Portal.

The service in question is shared within our organization.  I am an admin for the organization as well.

I updated the script as you have shown and now it seems to be working.  Thanks!

So the next step is how do I go about intersecting 2 services and creating a new summarized feature set to capture the number of point features within intersecting polygons?

0 Kudos
jcarlson
MVP Esteemed Contributor

Spatially intersecting two layers works the same, regardless of where the two layers come from. Here's a rough idea of what this would look like, though you'll need to make some adjustments.

 

var p1 = Portal('portal-url')
var p2 = Portal('agol-url')

// your portal fs; i'm assuming that this is the polygon layer
var fs1 = FeatureSetByPortalItem(
    p1,
    'itemid',
    0,false
    ['objectid'],
    true
);

// your agol fs
var fs2 = FeatureSetByPortalItem(
    p2,
    'itemid',
    0,
    ['objectid'],
    false
);

// output dict
var out_dict = {
    fields: [
        {name: 'polygon_id', type: 'esriFieldTypeString'},
        {name: 'point_count', type: 'esriFieldTypeInteger'}
    ],
    geometryType: '',
    features: []
}

// loop through polygons, get points
for (var f in fs1) {
    var xs_pts = Intersects(f, fs2)
    
    Push(
        out_dict['features'],
        {
            attributes: {
                polygon_id: f['objectid'],
                point_count: Count(xs_pts)
            }
        }
    )
}

return FeatureSet(Text(out_dict))

 

- Josh Carlson
Kendall County GIS
ghaskett_aaic
New Contributor II

Thanks again for your help on this.

I updated my script to the following and while the returned numbers seemed valid when testing, the return lacks information in the SIZE and RISKCNT fields.

What am I doing wrong?

var p = Portal('https://maps.xxxxx.com/portal/')
var sql = "(DATE > CURRENT_DATE - 7)"
var sqlST = "(STATE = 'CO')"

// the polygon layer
var fsHail = FeatureSetByPortalItem(p, 
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
0, ['label', 'SIZE', 'DATE_TEXT'], true
);

var fHail = Filter(fsHail, sql);

// the pts layer
var fsInforce = FeatureSetByPortalItem(p, 
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
0, ['PolicyNumber', 'LocationID', 'LOB', 'TIV', 'RiskCount'], false
);

var fInforce = Filter(fsInforce, sqlST);
/*Count(fInforce);*/

// output dict
var out_dict = {
    fields: [
        {name:'SIZE', type:'esriFieldTypeInteger'}, 
        {name:'RISKCNT', type:'esriFieldTypeInteger'}
    ],
    geometryType: '', 
    features:[]
}

// loop through polygons, get points
for (var f in fHail) {
    var xs_pts = Intersects(f, fInforce)
    Push(
        out_dict['features'],
        {
            attributes: [
                {
                    SIZE: f['SIZE'],
                    RISKCNT: Count(xs_pts)
                }
            ]
        }
    )
}
return FeatureSet(Text(out_dict))

 

 

0 Kudos
jcarlson
MVP Esteemed Contributor

attributes is a dict, not an array, and I realize I had that wrong in my expression.

It should be:

{
attributes: {
SIZE: f['SIZE'],
RISKCNT: Count(xs_pts)
}
}

I will update my post accordingly.

- Josh Carlson
Kendall County GIS