Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Understanding how file upload script inside a subform works with LiveCycle


Level 3

Good afternoon;

I have a form that I'm working on that requires a file upload script. I incorporated it based on the sample on this thread (https://forums.adobe.com/message/1976160#1976160). The form has hidden subforms so there's some heirarchy going on but I'm not able to figure out how to factor that into the script so the form allows the user to find the file and attach it, etc.

How would I modify the script in the sample for subforms? What am I missing?

I appreciate your help.

3 Replies


Level 10

Do you want to add an attachment to your file via scriptings? Where do you want to use the fiorm finally – Adobe Reader or Acrobat? For the former you'll need a LiveCycle server with the Reader Extensions module to enable this function in the form, for the latter, you can use the importDataObject() method i.e.

event.target.importDataObject({cName: "Image.jpeg"});


Level 3

Hello, thank you for your response.

I was able to get a slightly better understanding based off combining this thread (https://forums.adobe.com/thread/1235441) with this one (https://forums.adobe.com/message/10056473). Again; might make perfect sense for some but I'm still growing in coding. I was just happy to get it to work. Now, it could certainly be coded better, but for now, my client seems happy with the solution. As time permits (and if projects EVER slow down enough to allow), I'll try and get a better understanding of what's going on in the code and modify it so that it incorporates some more validation, control, etc.

Here's what I used for each of the buttons for attaching, opening, and removing file(s):

Attach button:

// attach file to form

var myDoc = event.target;

var sFile = "MyAttachedFile";

myDoc.importDataObject({cName: sFile});

var myDataObject = myDoc.getDataObject(sFile);

var sFileName = myDataObject.path;


Open button:

// open attachment in separate instance


var myDoc = event.target;

var sFile = Main.sfAttachmentRequest.attachmentsList.rawValue;

myDoc.exportDataObject({ cName: sFile, nLaunch: 2 });

} catch(e) {

app.alert("There are no files to open");


Remove button:

// remove attachment from listbox

var myDoc = event.target;

var sFile = Main.sfAttachmentRequest.attachmentsList.rawValue;

app.alert("You have removed the highlighted file from the form",1);



var myRemoveObject = event.target;

var a = myRemoveObject.getField("Main.sfAttachmentRequest.attachmentsList");

a.deleteItemAt(); // delete current item, and...

a.currentValueIndices = 0;


The example I built this from uses a list box to display the attached files which is great if attaching multiple files, but I'd like to figure out how to modify it for only attaching/displaying single files, as well. Probably a simple change.


Level 3

LOL, check this out...

All that work only to find out that the attach button won't work on Reader Extended forms without the LC extension...