Select to view content in your preferred language

ArcGIS Online Layer Query

3668
12
Jump to solution
02-13-2018 09:51 AM
ChrisKemmerer
Emerging Contributor

I have a hosted FeatureLayer in a Webmap that contains multiple features for data collections that will be used across multiple projects.  I'd like to be able to pull down data and attachments from those layers using a layer query in the create replica wizard .  For this example I have layers 0-3, all layers have a common attribute, "Project_Number".  I would like to do something similar to the example below.  So far I have tested the first line, while it produces a url to download the data the replica creation fails.  Unfortunately it does not provide an error number, only that it failed.  Any insight would be greatly appreciated.

EXAMPLE:

{"0":{"where":"Project_Number=842"}}
{"1":{"where":"Project_Number=842"}}
{"2":{"where":"Project_Number=842"}}
{"3":{"where":"Project_Number=842"}}

CHECK REPLICA STATUS ERROR:

2 Solutions

Accepted Solutions
HemantAngarkar
Occasional Contributor

Hi Chris,

Try using these for LayerQueries;

{"4":{"where":"TEAM='1'"}}

I think you need to use single quotes (' ') to enter values for where clause. Doesn't matter if it is Numeric or string field. I tried the same on my service and I could download the attachments.

1. Data tab of service

2. Query: {"0":{"where":"NUMBER='100'"}}

Please let me know if it works.

Best,

Hemant A

View solution in original post

GaryWorley1
Emerging Contributor

Figured this out.

 

•{"0":{"where":"Project_Number=842'", "where":"Project_Number=845'", "where":"Project_Number=895'"}}

View solution in original post

0 Kudos
12 Replies
by Anonymous User
Not applicable
  1. Does the create replica work if you leave the layer query out of the equation? 
  2. Are you creating the replica from the REST url? Could you put a screenshot for how you fill out the other parameters involved in creating a replica from REST?
  3. Perhaps this article can offer some guidance: How To: Retrieve attachments from a hosted feature service 
ChrisKemmerer
Emerging Contributor

Supriya, thank you so much for responding to my post.  Yes, the create replica works when the query is left out. I am Creating the replica from the Rest url, see below.  You'll notice the url appears as it should.  When I click the url I get a failed status and error. 

0 Kudos
by Anonymous User
Not applicable

Do any of the records in layer 4 (above) actually have attachments? I found that if I tried something similar to what you showed in the screenshot above on a layer that didn't have any attachments I got the "Error: Exporting data for layer X failed". But, if I tried the same thing above on a layer with attachments it succeeded. 

ChrisKemmerer
Emerging Contributor

All records in Layer 4 have attachments.  Could there be something in the feature layer settings that I'm overlooking that doesn't allow features & attachments to be downloaded with a query?

0 Kudos
HemantAngarkar
Occasional Contributor

Hi Chris,

Try using these for LayerQueries;

{"4":{"where":"TEAM='1'"}}

I think you need to use single quotes (' ') to enter values for where clause. Doesn't matter if it is Numeric or string field. I tried the same on my service and I could download the attachments.

1. Data tab of service

2. Query: {"0":{"where":"NUMBER='100'"}}

Please let me know if it works.

Best,

Hemant A

ChrisKemmerer
Emerging Contributor

Hemant, thank you so much.  The query string work flawlessly.  Thanks again!

ChrisKemmerer
Emerging Contributor

Sorry for the multiple replies.  How would you string together the query if you wanted to pull Team 1's data from multiple layers?   Lets say layers 4 & 7?

0 Kudos
by Anonymous User
Not applicable

You would add it to the original line, but keep it inside that first bracket. Look at this example here:

Syntax: layerQueries={ Layer_or_tableID1 : {"where":"attribute query" , "useGeometry" : true | false, "includeRelated" : true | false}, Layer_or_tableID2: {.}}

Create Replica—ArcGIS REST API: Services Directory | ArcGIS for Developers 

So if I took the first example you posted in this thread and corrected it, it would look something like this:

{"0":{"where":"Project_Number='842'"}, "1":{"where":"Project_Number='842'"}, "2":{"where":"Project_Number='842'"}, "3":{"where":"Project_Number='842'"}}

by Anonymous User
Not applicable

I had too many brackets in the response above. Just fixed it.

0 Kudos