You are viewing limited content. For full access, please sign in.

Question

Question

Populate a drop-down list with file names from a file upload field

asked on August 22, 2024 Show version history

Running Laserfiche Forms Professional Version 11.0.2212.30987...

I have a process that users will submit contract files for review. On the initial form, they'll upload contract files and specify sections from the uploaded files to be reviewed. In a table on that form, they will add a row for each section of each uploaded file. The table contains the following fields:

  1. File name (of one of the uploaded files)
  2. Start Page (page #)
  3. Language (manually copied from specific sections of the uploaded files)
  4. Issue (drop-down containing "Limit of Liability", "Payment Terms", "Unspecified Future Obligation", "Warranties")

Instead of having the user manually enter the file name, I'd like it to automatically populate the file names of the files that were uploaded to the file upload field. Is that possible to do all in the same initial form?

I thought about adding a Collection instead of a Table, but I call a workflow later on in the process that pulls the information into a Microsoft Word document via mail merge. I know how to pull data from a Table into mail merge, but not from a Collection.

If there's a better way to tackle this, please feel free to suggest another route.

0 0

Answer

SELECTED ANSWER
replied on August 30, 2024

The thing about Workflow being able to work with a Table versus a Collection shouldn't be an issue - Workflow will handle either the same way.

As far as the behavior you are wanting to populate the files from the upload into a dropdown field - that also won't matter whether you use a collection or table.  Although there are some structural differences between them, that shouldn't matter for this purpose.

The following Javascript should meet your needs in the Modern Designer.  I tested this on Forms 11 Update 5 (11.0.2311) and you indicated you are on Forms 11 Update 3 (11.0.2212) - therefore, it is possible this Javascript will not work without upgrading.  I can't say for sure whether or not all of the functionality was available on Update 3, but I suspect it was not all available yet.  I definitely recommend updating to Update 5 if you can, not just for this, but for a large selection of other additions that were made to the Modern Designer.

This Javascript assumes you have a single upload field on your form.  It assumes the dropdown field is contained within a table or collection.

Preparation:

  1. Determine the Field ID of the upload field - you'll populate that number in line 2 of the Javascript (instead of 1 that I have listed).
  2. Determine the Field ID of the dropdown fields in your table - you'll populate that number in line 3 of the Javascript (instead of 8 that I have listed).
  3. Determine the variable name of the table and the dropdown field - you'll need it for step #4.
  4. Add a number field to your form (you can use field rules to hide it).  Add the following formula to the number field (being sure to update the two references to TableVariable.DropDownVariable with the table and drop down variables you determined in step #3. 
    =COUNTIF(TableVariable.DropDownVariable, "<>") + COUNTIF(TableVariable.DropDownVariable, "=")
    
  5. Determine the Field ID of the number field you created in step #4 - you'll populate that number in line 4 of the Javascript (instead of 10 that I have listed).
  6. Add this Javascript to your form: 
//Populate the ID values for the fields on the form.
let uploadFieldID = 1;
let dropDownFieldID = 8;
let tableRowCountFieldID = 10;

//Trigger the function on form load and upload
//field changes.
UpdateDropDownOptions();
LFForm.onFieldChange(UpdateDropDownOptions, {fieldId: uploadFieldID});

//Trigger the function when table rows are added or
//deleted.  There is no LFForm event yet for adding
//and deleting rows, so this serves that purpose.
LFForm.onFieldChange(handleRowChange, {fieldId: tableRowCountFieldID});
let previousRowCount = LFForm.getFieldValues({fieldId: tableRowCountFieldID});
function handleRowChange() {
  const newRowCount = LFForm.getFieldValues({fieldId: tableRowCountFieldID});
  if (newRowCount < previousRowCount) {
    //row deleted
    UpdateDropDownOptions();
  } else if (newRowCount > previousRowCount) {
    //row added
    UpdateDropDownOptions();
  }
  previousRowCount = newRowCount;
}

//Function to update the file list and load
//it as the options in the dropdown fields.
function UpdateDropDownOptions() {
  let uploadList = LFForm.getFieldValues({fieldId: uploadFieldID});
  let fileList = [];
  uploadList.forEach(function(element) {
    fileList.push(element.name);
  });
  let dropDownFields = LFForm.findFieldsByFieldId(dropDownFieldID);
  dropDownFields.forEach(function(element) {
    LFForm.changeFieldOptions(element, fileList, "replace" );
  });
}

 

1 0

Replies

replied on September 3, 2024

The table row count field works. I think you're correct in that I need to upgrade my Laserfiche Forms version to version 11 update 5. I will update this post after I upgrade and test again.

Thank you so much for the detailed instructions. Very easy to follow!

1 0
replied on September 5, 2024

Yay! I updated to Laserfiche Forms 11 Update 5 and it works now. Thank you!!

1 0
replied on September 5, 2024

That's fantastic!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.