Setting the document template(s) to be assembled with Script

As a general rule the template that gets assembled will be the template that you upload to your form (or multiform).

However, in some cases you may want to override what template gets assembled by a particular form or multiform.

In this case you can use script to set the template, or templates that get assembled. You can also use conditional logic in the script to select a particular template based on answers to questions on the form.

This Script should be included in the Form Script for a Form within the project that will always be opened at least once, (usually the the Form in a single Form project, or the first Form in a Multi-Form project).

To trigger the change of template from the default form template to the script template, you need to trigger a system event when the form is submitted by the user. You do this with the following script:

//This function is triggered by the user clicking submit. It runs before the documents are assembled

function BeforeAssembly(){ 
    setFormURLs();
}

The above system event then calls the setFormURLs function. You also need to define the function in the script, as follows:

//This is the function that is triggered by the assembled event above, and is where the templates are set

function setFormURLs(){
    
    var FormURLs = '';   //This clears the variable FormURLs 
   
    FormURLs = "http://create.zumeforms.com/Users/demo/Templates/TemplateA.doc"; //This sets the variable FormURLs to one document
    
    $('#DocumentTemplateURL').val(FormURLs);  //This then sets the field that governs assembly to the selected URL values
 
}

If you want to set more than one template, then you need to separate them with a ‘,’ (comma) as follows:

//This is the function that is triggered by the assembled event above, and is where the templates are set

function setFormURLs(){
    
    var FormURLs = '';   //This clears the variable FormURLs 
   
    FormURLs = "http://create.zumeforms.com/Users/demo/Templates/TemplateA.doc,http://create.zumeforms.com/Users/demo/Templates/TemplateB.doc"; //This sets the variable FormURLs to two documents
    
    $('#DocumentTemplateURL').val(FormURLs);  //This then sets the field that governs assembly to the selected URL values
 
}

If you want to include some conditional logic in your script to choose between two templates, then you would do something along these lines:

//This is the function that is triggered by the assembled event above, and is where the templates are set

function setFormURLs(){ 

var FormURLs = ''; //This clears the variable FormURLs
var choice = fld('choice_cho').val(); //This sets the variable choice to the value of the choice_cho field

if(choice == 'A'){ 
    FormURLs = "http://create.zumeforms.com/Users/demo/Templates/TemplateA.doc"; //This sets the variable FormURLs to one document 
} 

if(choice == 'B'){
    FormURLs = "http://create.zumeforms.com/Users/demo/Templates/TemplateB.doc";
}
    
$('#DocumentTemplateURL').val(FormURLs);  //This then sets the field that governs assembly to the selected URL values

}

Click here to see an example Form where only one template is selected.

This is the Script you would use to select multiple templates to be assembled:

function BeforeAssembly(){ 
    setFormURLs();
}

function setFormURLs(){
    
    var FormURLs = '';    
    var num = fld('number_num').val();
    
    if(num > 1){        
            FormURLs += ",http://create.zumeforms.com/Users/demo/Templates/TemplateA.doc"; 
    }    

    if(num > 2){        
            FormURLs += ",http://create.zumeforms.com/Users/demo/Templates/TemplateB.doc"; 
    }

    if(num > 3){        
            FormURLs += ",http://create.zumeforms.com/Users/demo/Templates/TemplateC.doc"; 
    }
    
    FormURLs = FormURLs.substring(1);  // This line of script is required to strip the first comma off the assembled URL
    $('#DocumentTemplateURL').val(FormURLs);
 
}

Click here to see an example Form where multiple templates are selected.