Select to view content in your preferred language

How to get the number of attachments in an attribute table, including the format of each attachment.

528
0
12-26-2024 09:45 AM
Bilal_Alam_GIS
Occasional Contributor
5 0 528

In ArcGIS Pro, you can attach different types of files to a feature class stored in a geodatabase. If you only need the count of the attachments without details about their formats, please refer to the ESRI Technical Support document titled "Display the number of attachments in an attribute table using Arcade in ArcGIS Pro". However, if you also need the format of each attachment, please follow the process outlined below:

Procedure.

  1. Open the project in ArcGIS Pro.
  2. Add a new field to the feature class containing attachments. Name this field "Attachment Count With Format" and set its type to Text.
  3. Field.png

     Open the attribute table, right-click on the newly added field "Attachment Count With Format", and         select "Calculate Field".

  4. Change the expression type to Arcade and copy and paste the following code. You can add more             formats as needed:

Field2.png

 

 

var attachments = Attachments($feature);
var jpeg_count = 0;
var jpg_count = 0;
var m4a_count = 0;
var mp3_count = 0;
var mp4_count = 0;
var ogg_count = 0;
var opus_count = 0;
var png_count = 0;
var tif_count = 0;
var wav_count = 0;
var other_count = 0;

for (var i in attachments) {
var attach = attachments[i];
var file_extension = Upper(Right(attach.name, 4));

if (file_extension == ".JPEG") {
jpeg_count += 1;
} else if (file_extension == ".JPG") {
jpg_count += 1;
} else if (file_extension == ".M4A") {
m4a_count += 1;
} else if (file_extension == ".MP3") {
mp3_count += 1;
} else if (file_extension == ".MP4") {
mp4_count += 1;
} else if (file_extension == ".OGG") {
ogg_count += 1;
} else if (file_extension == ".OPUS") {
opus_count += 1;
} else if (file_extension == ".PNG") {
png_count += 1;
} else if (file_extension == ".TIF" || file_extension == ".TIFF") {  // Also count .TIFF as .TIF
tif_count += 1;
} else if (file_extension == ".WAV") {
wav_count += 1;
} else {
other_count += 1;
}
}

var result = "JPEG: " + Text(jpeg_count) + ", JPG: " + Text(jpg_count) + ", M4A: " + Text(m4a_count) +
", MP3: " + Text(mp3_count) + ", MP4: " + Text(mp4_count) + ", OGG: " + Text(ogg_count) +
", OPUS: " + Text(opus_count) + ", PNG: " + Text(png_count) + ", TIF: " + Text(tif_count) +
", WAV: " + Text(wav_count) + ", Other: " + Text(other_count);

return result;

 

 

      5. It will give you the result as shown below in the attribute table.

Bilal_Alam_GIS_5-1734847363685.png

 

Contributors