Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

You may find a need to combine the data from multiple form components.  Consider the example below:

For consistency, you may want to capture first name, last name, and middle initial as separate components, but when mapping that data to a PDF you want to map the person's full name on the document.  You can separately map each individual form component, but that might result in issues with form data overlapping or inconsistent spacing.  This will depend on how the destination document is laid out.  Regardless of the reason, if you want to combine the values of multiple components into a single value, there is some basic Javascript syntax to do the job.

Start by adding a form component to receive the combined data.  Remember, if you don't need to see the data on the form, you can mark the new components as hidden.  The data from hidden components can be mapped to PDFs, even though they are not shown.  For testing purposes, it is recommended you mark the component as hidden after you have confirmed your logic is working at the correct data is showing.  Open the settings of the destination component and click the Data tab.  Click the Calculated Value section to open the script editor.  Here you can write the logic to concatenate the values.  

Remember you will need to reference the individual component Property Names, found on the API tab for each component.  In the example above, each element of interest is named based on its label in camel case.  So the First Name component has a property name of firstName, Last Name has a property name of lastName, and Middle Initial has a property name of middleInitial.

When writing a Calculated Value rule in Javascript, a system variable is predefined to receive the data called value.  The value variable must be set in the rule to assign the data into the component of interest.

Name Concatenation Rule
var fullName = ''; //Initialize a variable to store the data

if(data.firstName) //If there is data, assign it to fullName with a trailing space
    fullName = data.firstName + ' ';
    
if (data.middleInitial) //If there is data, append it to fullName with a trailing space
    fullName += data.middleInitial + ' ';
    
if (data.lastName) //If there is data, append it to full name
    fullName += data.lastName;

value = fullName.trim();  //Trim off any trailing spaces and assign the data to the 'value' variable


  • No labels