Home > Products > BPC PowerForms > Knowledge Base > Scripting > Handling the AttachmentsLoaded event

Handling the AttachmentsLoaded event

The "form" object available from script, exposes a specific event that is raised after the item attachments are loaded.

The event is called "AttachmentsLoaded" and provide a list of the available item attachments. For each attachment, the "Filename" and "FullPath" properties provide access to file attributes.


For the following example, we will handle the event, select all the images from the available attachments and display thumbnails inside our form.

First place a label on the form named "c_Thumbs".

Next, inside the designer, go to the Options > Scripting > LoadCompleted script and add something like the following :


form.AttachmentsLoaded.AddHandler(function(files) {
   var s = "";

   // get a reference to the label control
   var c = form.GetControl("c_Thumbs");
   for (var i=0;i<files.length;i++) {
    var name = files[i].FullPath;

    // filter results by suffix (images only)
    var suf = name.substring(name.length - 3, name.length).toLowerCase();
    if (suf == "png" || suf == "gif" || suf == "jpg" || suf == "bmp")
      s = s + "<span style='padding:10px'><a href='" + files[i].FullPath + "' target='_blank' style=''><img src='" + files[i].FullPath + "' width='32' height='32' style='border:0px' /></a></span>"

Here is the final result :