Using Formstack Documents, interact with files from Salesforce to build your PDFs. Prior to managing these files, please consider:
- Files can be mapped and accessed directly from Salesforce Mappings for:
- the Primary Object
- any Related Lookup Objects
- When mapping Files, any fields on the Content Version object are accessible within Formstack Documents, including custom fields.
Use Cases
Combine All Attached Files into a Single PDF
Sort Attached Files Before Combining into a Single PDF
Filter Attached Files to Combine into a Single PDF
Combine All Attached Files into a Single PDF
The files associated with a record in Salesforce can be included in a combined PDF generated in Formstack Documents. Follow these steps:
Step 1: In the Formstack Documents tab, click Data Routing in the Formstack Documents header and create a new data route by clicking New Data Route.
Step 2: In the popup, give the data route a name and click Create Data Route.
Step 3: Go to the Rules tab and add a new rule. (When creating a new data route, three empty rules will be added. One of these rules can be used and remove the rest.) Check Repeat this rule in the bottom right of the rule box. A new input field will appear in the rule.
Step 4: In the Send data to Document dropdown, select <
Step 5: In the Send data to Document field, type {$Url}. The merge field must match exactly (case-sensitive) in order for the Files to attach properly.
Step 6: In the Repeat this rule using the field (array) field use the merge field syntax and name the field anything. This will be the field we map in Salesforce Mappings later. In this example, {$Files} is used.
Please note: There is a limit of 10 files that can be delivered as part of a Child Relationship files configuration.
Step 7: Check Include in combined PDF in the middle of the rule at the bottom. At this point, the rule should look like the following screenshot. The rule may have a different merge field name in the Repeat this rule using the field (array) field.
Step 8: Click Save, Next to save the rule.
Step 9: Go to the Formstack Mappings tab in Salesforce and click + New Mapping in the top right corner.
Step 10: A new mapping screen will appear. Give the mapping a Name and optionally a Description.
Step 11: Select the Salesforce Object to use as the Primary Object. This has to be the object that has the files attached to it or a lookup field to the object that has the files attached to it.
Step 12: Select Route as the Formstack Resource and select the route previously created from the dropdown as the Data Route. The new mapping should look like the following screenshot. The Salesforce Object and Data Route will vary.
Step 13: Click Save and Next.
Step 14: The fields available for mapping will load. This will include the Url field as well as the field created for the array of files. In this example, it is Files. Do not map any Salesforce fields to Url. Map the appropriate Files relationship into the array field. In the following screenshot, Child Relationship: Files (the files attached to the primary object, Contact) is mapped to Files.
Step 15: Click Save and Activate. The mapping is now ready for use.
Sort Attached Files Before Combining into a Single PDF
When adding files associated with a record in Salesforce to a combined PDF, they can be sorted by any field, standard or custom, on the Content Version object. Follow these steps:
Step 1: Setup the data route following the steps of the first use case.
Step 2: In the rule Repeat this rule using the field (array), add the appropriate modifier after the merge field name. Use the sort or multisort modifiers to adjust the order of the array of files.
- Sort (one field): To apply the sort modifier, add the pipe character ( | ) immediately following the merge field name, the word sort, a colon ( : ) and the API name of the field to use for sorting in single or double quotes ( ‘ or “ ).
- Descending order: By default, the list will be sorted in ascending order, but to sort in descending order, add another colon ( : ) and the word desc in single or double quotes ( ‘ or “ ).
- Multisort (multiple fields): To apply the multisort modifier, use the word multisort rather than sort. Then, in a similar way, add each field, separated by a colon ( : ) using its API name in single or double quotes ( ‘ or “ ) followed by a colon ( : ) and the sort order (asc or desc).
Note: When attempting to use multisort and one of the fields being used for sorting is blank, the following error may be received:
Error: We're sorry, but an error has occurred: array_multisort(): Array sizes are inconsistent. Please try again.
When a field is blank in Salesforce, it will not always be returned in the API. This will cause the multisport format to fail.
Filter Attached Files to Combine into a Single PDF
Conditional logic can be used with the rules to filter out specific Files to merge into the combined PDF. This logic can include any merge field in the mapping or standard or custom field on the Content Version object in Salesforce. Follow these steps:
Step 1: Setup the data route following the steps of the first use case.
Step 2: In the rule in Send data to Document, add an if condition merge tag around the URL merge tag ( {$Url} ). If {$Url} already exists in the field, select <
Step 3: In the condition of the if tag, reference the merge field using the Formstack Documents syntax of dollar sign ( $ ) and then the name of the merge field. If referencing a field on the Content Version object, use the exact API name. It is case-sensitive.
Have any further questions? We’re here to help! Please reach out to support@formstack.com for additional assistance with your use case.
Are you looking for consultation or help building out your use case(s)? Team up with third party Certified Formstack experts to bring your custom projects to life.