<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Add feature with attachment in single step in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-feature-with-attachment-in-single-step/m-p/1418184#M84480</link>
    <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes it can be done. You need to create a new feature with a globalId and use that globalId for the attachments all in one applyEdits method. You applyEdits param would look something like the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const edits = {
  addFeatures: new Collection(addFeatures),
  deleteFeatures: deleteFeatures,

  addAttachments: addAttachments,
  updateAttachments: updateAttachments,
  deleteAttachments: deleteAttachments
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where where the new Feature has a new global id attribute set... something like&amp;nbsp;&lt;SPAN class=""&gt;GlobalID&lt;/SPAN&gt;&lt;SPAN class=""&gt;: &lt;/SPAN&gt;&lt;SPAN class=""&gt;"f0e2d7a2-b1b7-4f34-a080-c87286001e39"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Then your addAttachments array has a new attachment as created something like below:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;addAttachments.push({
  feature: newFeature,
  attachment: {
    globalId: f0e2d7a2-b1b7-4f34-a080-c87286001e39,
    name: "your attachment name,
    data: input.files[0] || blob
  }
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Notice that the globalId of the attachment matches the global id of the new feature you are creating. Then just call applyEdits with those two params set on `edits` param. Hope this makes sense.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 02 May 2024 15:57:53 GMT</pubDate>
    <dc:creator>UndralBatsukh</dc:creator>
    <dc:date>2024-05-02T15:57:53Z</dc:date>
    <item>
      <title>Add feature with attachment in single step</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-feature-with-attachment-in-single-step/m-p/1416003#M84426</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;is there a way in ArcGIS Maps SDK for JavaScript how to add new feature with attachments to FeatureService in single step (using only one HTTP request in the background).&lt;/P&gt;&lt;P&gt;Currently, I'm able to do it by using the applyEdits() method, which adds the new feature, then I make a query based on the globalid of this new feature and use the addAttachment() method to join attachments.&lt;/P&gt;&lt;P&gt;applyEdits() method has a parameter&amp;nbsp;&lt;SPAN class=""&gt;addAttachments in the API documentation, too. Howewer, I think that I still need to know the globalid in that case. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;Ideally&lt;/SPAN&gt;, I would only need to make one request for some reasons.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Thank for replies.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 06:49:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-feature-with-attachment-in-single-step/m-p/1416003#M84426</guid>
      <dc:creator>KamilNovák</dc:creator>
      <dc:date>2024-04-27T06:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: Add feature with attachment in single step</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-feature-with-attachment-in-single-step/m-p/1418184#M84480</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes it can be done. You need to create a new feature with a globalId and use that globalId for the attachments all in one applyEdits method. You applyEdits param would look something like the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const edits = {
  addFeatures: new Collection(addFeatures),
  deleteFeatures: deleteFeatures,

  addAttachments: addAttachments,
  updateAttachments: updateAttachments,
  deleteAttachments: deleteAttachments
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where where the new Feature has a new global id attribute set... something like&amp;nbsp;&lt;SPAN class=""&gt;GlobalID&lt;/SPAN&gt;&lt;SPAN class=""&gt;: &lt;/SPAN&gt;&lt;SPAN class=""&gt;"f0e2d7a2-b1b7-4f34-a080-c87286001e39"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Then your addAttachments array has a new attachment as created something like below:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;addAttachments.push({
  feature: newFeature,
  attachment: {
    globalId: f0e2d7a2-b1b7-4f34-a080-c87286001e39,
    name: "your attachment name,
    data: input.files[0] || blob
  }
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Notice that the globalId of the attachment matches the global id of the new feature you are creating. Then just call applyEdits with those two params set on `edits` param. Hope this makes sense.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2024 15:57:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-feature-with-attachment-in-single-step/m-p/1418184#M84480</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2024-05-02T15:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: Add feature with attachment in single step</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-feature-with-attachment-in-single-step/m-p/1418256#M84487</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/53756"&gt;@UndralBatsukh&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Thank you for your reply. I understand how to create applyEdits with parameters, as you described.&lt;/P&gt;&lt;P&gt;However, I’m a bit confused about where to obtain the globalid when creating a new feature on the client side. I believe that the globalid is assigned in the geodatabase. Can I use my own globalid? If so, how can I ensure that it will be unique in the geodatabase?&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2024 17:54:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-feature-with-attachment-in-single-step/m-p/1418256#M84487</guid>
      <dc:creator>KamilNovák</dc:creator>
      <dc:date>2024-05-02T17:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: Add feature with attachment in single step</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-feature-with-attachment-in-single-step/m-p/1418274#M84488</link>
      <description>&lt;P&gt;Yes you create the globalId yourself. You could use one of the guid generators.&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2024 18:29:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-feature-with-attachment-in-single-step/m-p/1418274#M84488</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2024-05-02T18:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: Add feature with attachment in single step</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-feature-with-attachment-in-single-step/m-p/1418559#M84494</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/53756"&gt;@UndralBatsukh&lt;/a&gt;&amp;nbsp; thank you for this information. I didn't know this strategy.&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2024 06:20:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-feature-with-attachment-in-single-step/m-p/1418559#M84494</guid>
      <dc:creator>KamilNovák</dc:creator>
      <dc:date>2024-05-03T06:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Add feature with attachment in single step</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-feature-with-attachment-in-single-step/m-p/1419027#M84510</link>
      <description>&lt;P&gt;Hi &lt;A href="https://community.esri.com/t5/user/viewprofilepage/user-id/53756" target="_blank" rel="noopener"&gt;@UndralBatsukh&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;can I have another question about this problem. I have finished my applyEdits() method. Its logic &lt;SPAN&gt;aligns with the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;featureForSend.setAttribute("globalid", "{3b0931f2-78f6-4799-ae0f-13d26c787775}");
EditLayer.applyEdits({
  addFeatures: [featureForSend], 
  addAttachments: [{
     feature: featureForSend,
     attachment: {
        globalId: "{b99a53f2-3b76-4024-97d2-8ceca8b624ae}",
        data: input.files[0]
     }
   }]
}, {gdbVersion: "", 
    returnEditMoment: false, 
    globalIdUsed: true, 
    rollbackOnFailureEnabled: false
}).then((result) =&amp;gt; {...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This code fires HTTP request with this data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;Adds:
[{"geometry":{"spatialReference":{"latestWkid":5514,"wkid":102067},"x":-8988283.904533692,"y":4133042.200104993},"attributes":{"poznamka": "test", "globalid":"{3b0931f2-78f6-4799-ae0f-13d26c787775}"}}]

Attachments:
{"adds":[{"globalId":"{b99a53f2-3b76-4024-97d2-8ceca8b624ae}","parentGlobalId":"{3b0931f2-78f6-4799-ae0f-13d26c787775}","contentType":"image/png","name":"Image 001.png","uploadId":null,"data":"loremipsum"}],"updates":[],"deletes":[]}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... and it ends with server error "Unable to complete operation. Unable to perform applyEdits operation. An error occurred."&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I’ve discovered an issue related to the&lt;/SPAN&gt; &lt;STRONG&gt;"uploadId":null&amp;nbsp;&lt;/STRONG&gt;parameter (in Attachments data). When I remove this parametr and re-run this request again (directly in REST API), &lt;SPAN&gt;the request succeeds&lt;/SPAN&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However I'm not able to &lt;SPAN&gt;achieve&lt;/SPAN&gt; &lt;SPAN&gt;the same result using the&lt;/SPAN&gt; ArcGIS Maps SDK fo JavaScript. JS API always adds this &lt;STRONG&gt;"uploadId":null &lt;/STRONG&gt;param to the HTTP request.&lt;/P&gt;&lt;P data-unlink="true"&gt;Is there a solution for this?&amp;nbsp; We have federated Enterprise 10.9.1 and JS API 4.27.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2024 15:01:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-feature-with-attachment-in-single-step/m-p/1419027#M84510</guid>
      <dc:creator>KamilNovák</dc:creator>
      <dc:date>2024-05-04T15:01:18Z</dc:date>
    </item>
  </channel>
</rss>

