Select to view content in your preferred language

Adding Attachment triggers ApplyEdits - Infinite Loop

1891
5
Jump to solution
11-17-2020 02:59 PM
by Anonymous User
Not applicable

Hello,

I have a simple app that collects data with one of those being a signature captured as an image. I have an issue when I go to submit the data and create the record, the attachment code endless loops and keeps adding the attachment. 

My pseudo code looks like this:

1. Add Features to Feature Table

2. On Features Added, apply edits.

3. OnApplyEditsStatusChanged

  • Get the ObjectID of the newly created feature.
  • Select the new feature

4. OnSelectFeaturesStatusChanged, Add the attachment

 

Once the attachment is added, the onApplyEditsStatusChanged triggers causing a new selection which then in turn adds the attachment again and enters an infinite loop.

How do I not trigger the ApplyEdits after an attachment is added? or is there an entirely different way of approaching this problem?

 

0 Kudos
1 Solution

Accepted Solutions
LucasDanzinger
Esri Frequent Contributor

Yeah, you will need to code it differently since your signal handlers are all triggering each other in an endless loop. There are probably many ways to do it. For example, do you need to apply edits right after you add the feature? Could you select features from within your addFeatures signal handler, then when feature is selected, add attachments and apply edits (in this case, applyEdits signal handler wouldn't retrigger a selection). You could also add some type of bool or state to indicate what part of the workflow the user is in, and take different code paths depending on that.

View solution in original post

0 Kudos
5 Replies
ErwinSoekianto
Esri Alum

@Anonymous User ,

Are you using ArcGIS Runtime SDK for Qt inside AppStudio app, correct?

I think the Psuedo code looks good to me, can you share the actual code? 

I am including @LucasDanzinger  from ArcGIS Runtime SDK for Qt to see if there anything wrong with this. 

 

Thank you,

Erwin

0 Kudos
by Anonymous User
Not applicable
FeatureLayer{
                id: featurelayer


                 onSelectFeaturesStatusChanged: {

                     if (selectFeaturesStatus === Enums.TaskStatusCompleted) {
                       if (!selectFeaturesResult.iterator.hasNext)
                            return;
                       selectedFeature = selectFeaturesResult.iterator.next();
                       selectedFeature.attachments.addAttachment(attachment, "image/jpeg", 'Official.jpg');

                     }
                 }



                ServiceFeatureTable {
                    id:featureTable
                    url: serviceURL + "/0"
                    credential: portalCredential


                    QueryParameters{
                    id: params

                    }


                    onApplyEditsStatusChanged: {
                        if (applyEditsStatus === Enums.TaskStatusCompleted) {

                            params.objectIds = applyEditsResult[0]["objectId"]
                            featurelayer.selectFeaturesWithQuery(params, Enums.SelectionModeNew);
                        }


                    }


                    onAddFeaturesStatusChanged:{
                     if (addFeaturesStatus === Enums.TaskStatusCompleted) {
                            featureTable.applyEdits();
                            }
                        }



                 } //ServiceFeatureTable


            }//FeatureLayer

Above is my feature layer. Yes, I am using the ArcGIS Runtime SDK using AppStudio. Below is the import statement I'm using.

import Esri.ArcGISRuntime 100.1

 

0 Kudos
LucasDanzinger
Esri Frequent Contributor

If you set autoApplyEdits to false on the feature's AttachmentListModel, it shouldn't apply automatically and you can control when it happens. https://developers.arcgis.com/qt/latest/qml/api-reference/qml-esri-arcgisruntime-attachmentlistmodel... 

0 Kudos
by Anonymous User
Not applicable

Setting autoApplyEdits to false does stop the infinite loop, but the attachments don't get added until I turn back to true which then starts the infinite loop again.

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Yeah, you will need to code it differently since your signal handlers are all triggering each other in an endless loop. There are probably many ways to do it. For example, do you need to apply edits right after you add the feature? Could you select features from within your addFeatures signal handler, then when feature is selected, add attachments and apply edits (in this case, applyEdits signal handler wouldn't retrigger a selection). You could also add some type of bool or state to indicate what part of the workflow the user is in, and take different code paths depending on that.

0 Kudos