How to get file name or id from "File Upload" Control

Comments

8 comments

  • Avatar
    Karl Makatenas

    If you take a look at the schema for your File Upload control, you should see a few repeatable fields which have the data for each file.  Among them should be a name and a URL.

     

    From here, you'll need to do some fancy rules and/or JavaScript to grab their values if you need them in other parts of the form, but if you can wait until the process, there are plenty of AgilePoint Activities that can handle repeating schema elements easily.

    That should be a good starting point, but if you're still struggling, don't hesitate to post again.

    0
    Comment actions Permalink
  • Avatar
    SRL Support Team

    Hi,

    that's the problem. I tried to create simple/fancy rule to copy file url value to any other text field on the form but the rule doesn't work.

    I know that I can handle all uploaded file attributes in the process but in this specific case I'd like to get this value before starting a process.

    Thanks

    Marina

     

    0
    Comment actions Permalink
  • Avatar
    Karl Makatenas

    Ah, this can get annoying at times.  I wrote a bit of JavaScript to get what you need, and hopefully the pictures give you enough of an idea on how to modify it.  If you only have one attachment maximum, then the code works as-is, but if you need "n" attachments, you'll have to duplicate the function "n" number of times and fire "n" rules, then change what's in red.

    [code]

    function SetFieldToFileUploadValue(context, targetFields, dataNames) {
    debugger;
    var contextField = context.id;
    eFormHelper.getFieldValue(
    {fieldId: contextField},
    function(result) {
    var fileArray = result.data[contextField];
    for (var i = 0, len = dataNames.length; i < len; i++) {
    var data = fileArray[0][dataNames[i]];
    eFormHelper.setFieldValue({fieldId: targetFields[i], value: data});
    }
    }
    );
    }

    [/code]

    0
    Comment actions Permalink
  • Avatar
    SRL Support Team

    Hi,

    thanks. It works perfect

    Now, I'm trying to apply this JavaScript on fields inside the subform (for multiple rows). Should it work? Looks that there is a problem to get file upload object...Do you ant idea?

    0
    Comment actions Permalink
  • Avatar
    Karl Makatenas

    Is the File Upload, URL, and File Name section a repeatable subform?  If so, how many times can it repeat?

    If it can only repeat 2-3 times, then duplicating the function above and renaming it to something like
    SetFieldToFileUploadValue0
    SetFieldToFileUploadValue1
    SetFieldToFileUploadValue2
    and changing the red number above should do the trick, although it looks a bit ugly.  If it's repeating more than that, I'll have to get some time to mess with the :[this] variable to get it working for an arbitrary number of repeats.  I've got a lot of meetings today, so I may not be able to help much until tomorrow.

    0
    Comment actions Permalink
  • Avatar
    SRL Support Team

    Hi,

    yes, this is repeatable subform. In real scenario the number of rows in the subform is unlimited.

    The file upload is limited only for 1 file.

    I tried to apply your function on the first row in the subfrom and it does not work. I'm not sure where is the problem...

    Thanks

    Marina

    0
    Comment actions Permalink
  • Avatar
    Karl Makatenas

    Alright, I finally got this one working.

    https://pastebin.com/By3C1DWr 

    For a field outside of a subform, use this notation in the rule:
    ["TextBox1", "TextBox2"], ["url", "fileName"]

    For a field within a subform, use this notation in the rule:
    ["SubForm1/TextBox3", "SubForm1/TextBox4"], ["url", "fileName"]

    If you have a subform within a subform, although I haven't tried it, you can probably nest them like so: "SubForm1/SubForm2/Textbox5".

    0
    Comment actions Permalink
  • Avatar
    SRL Support Team

    Hi,

    Thanks a lot. I checked it on my side and it works.

     

    Regards,

    Marina

    0
    Comment actions Permalink

Please sign in to leave a comment.