How can I determine uniqueId of main feature using webhook response?

160
6
Jump to solution
08-06-2018 03:18 PM
MattStayner
New Contributor III

This is an easy task if you don't have repeats. When you introduce repeats, you get multiple addResults that each have an attribute of uniqueId (see attached responseMult.py) and it is not easy to tell which one belongs to the main layer and which ones belong to related tables. In the case of the attached results, the uniqueId is 3. It is different if there are no repeats (see attached responseSingle.py).

What logic can I use to write code that gets the correct uniqueId every time? Below are 3 approaches I'm considering.

Approach 1

Use the addResults with id: 0. That is the case in the 2 attached examples. Is that always true? Does id: 0 always reference the main layer and subsequent ids represent related tables? If that is always the case, then that is pretty simple.

Approach 2

If there is only 1 addResults then use the uniqueId of that addResults

If there is more than 1 addResults, then look up the parentglobalid in the adds and use that to lookup the globalId of the correct addResults. This is a little complicated, but should work.

Approach 3

Use layerInfo to get the id of the correct addResults. I have results from a webhook from a while ago that included layerInfo attributes, which included, among other things, the id of the layer. For some reason that is not included in the webhook responses, we get now. Any thoughts on why? It seems like this would be the best approach if we could be could get it turned back on.

Thoughts?

Thanks so much!

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JamesTedrick
Esri Esteemed Contributor

Hi Matt,

The parent record will be the addResults with the id (layer id) that matches the layer set by form_id. Default will be 0 for Surveys published through Survey123; it differs if you go through the steps of configuring a survey to use an existing feature service and modify the form_id to point to a different layer than 0.

View solution in original post

0 Kudos
6 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Matt,

The parent record will be the addResults with the id (layer id) that matches the layer set by form_id. Default will be 0 for Surveys published through Survey123; it differs if you go through the steps of configuring a survey to use an existing feature service and modify the form_id to point to a different layer than 0.

View solution in original post

0 Kudos
MattStayner
New Contributor III

Hi James!

So it sounds like I need to access the form definition and look up the form_id, then I will know with addResult to use. How can I programmatically look up the form_id in the form definition? I see form_id on the settings tab in the Connect Excel spreadsheet. It is blank on the few surveys that I created. Does a blank value mean the id is 0?

Thanks,

Matt

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Matt,

Yes, if blank it's the default state, which is layer 0.

0 Kudos
MattStayner
New Contributor III

James,

Thanks for the quick reply!

I see now how to manually look up the form_id. Is it possible to programmatically look up the form_id?

Thanks again,

Matt

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Right now, it would be a bit complicated - you could get the XForm XML file and read it from there.  I've added an enhancement to the webhook payload to provide the parent layer's ID.

0 Kudos
MattStayner
New Contributor III

James,

That would be great if the layer ID could be provided in the webhook payload. For now, we will just look it up manually.

Thanks for the quick responses!

Matt

0 Kudos