Share:
Developers » Script Examples by Type » Form Event Script Example

PREVIOUS  |  NEXT

Form Event Script Examples

Quick Links


See these other Form Event script examples for detailed steps on creating the script:

Notice: We are currently working to improve this content. Once revisions are finalized, we will add the article to the Recently Updated Articles section on the product's Documentation Home page. Learn more.


Workflow enables you to create Form Event scripts that you can use to configure custom field values and options, add and move custom fields on a form, and to create document templates. See the following code examples for syntax information.

Configure Custom Field without Predefined Values

[Back to top]

def cf = currentCase.getCustomField("First Name"); 
    form.addField(cf.getSystemId()); 
    form.setValue(cf.getSystemId(), "John"); 

    if (!cf.isEnabled()){ 
    cf.enable();  
    }

    if (!cf.isRequired()){ 
    cf.setRequired(true); 
    }

    if (cf.isHidden()){ 
    cf.setHidden(false); 
    }

Configure Custom Field with Predefined Values 

[Back to top]

def cf = form.getField('checkbox'); 

    cf.setPredefinedValues('Yes, No, Maybe'); 
    cf.setDisallowedValues('Maybe'); 
    cf.value='Yes'; //Yes will be preselected

Move and Add Custom Fields on Forms

[Back to top]

def cf1 = form.getField('product_or_model'); 
    cf1.moveBefore('long_term_fix');

    def cf2 = form.getField('warranty_status'); 
    cf2.moveAfter('reasons_for_rejection');

    form.addField('serial_number');

    def cf3 = form.getField('serial_number'); 
    cf3.moveBefore('long_term_fix');

Configure Custom Field Value Options

[Back to top]

def customValueOptions = currentCase.createValueOptions();
   customValueOptions.validatePredefinedValues = false;
   customValueOptions.convertToLowerCase = false;

   def a = 'Example'
   currentCase.setCustomField('autocomplete_field', 'a', customValueOptions)

Create Document Template

[Back to top]

def htmlContent = """
     <html>.... </html>
    """

   def dc = resp.createDocumentTemplate('document_template_system_id'); 
   dc.content = htmlContent; 
   dc.fileName = 'example.pdf';
   dc.setCase(currentCase);
   def report = dc.generate();



Related Articles