Edit a Transact Function Groovy Script

   Journey Manager (JM) The transaction engine for the platform.  |    Form Builder Platform Developer |  17.10 This feature was introduced in 17.10.

Manager allows you to edit a Groovy script, which implements the desired business logic of a Transact function. As you create a new Transact function, Manager generate a default Groovy script, so you must modify it.

Note

You can test your Groovy script or a part of the script using the Groovy console.

To edit the Groovy script:

  1. Select Services > Transact Functions.
  2. Locate a Transact function and click Edit.
  3. Click the Groovy Script tab to view the current script.
    Manager edit Groovy script

    While working on the script, you can use some basic editing options, such as:

    • Line numbering.
    • Ctrl-Z.
    • Ctrl-C and Ctrl-V.
    • Collapse and extend class, function and method definitions.
  4. Click the documentation links to get help on how to write Groovy scripts and which APIs to use.
  5. Click inside the Groovy script to start editing it. For example, you can replace the default script with the simple script shown below:
    
    import com.avoka.tm.func.*
    import com.avoka.tm.util.*
    import com.avoka.tm.vo.*
    import javax.servlet.http.*
    					
    class FluentFunction {
    	// Injected at runtime
    	public Logger logger
    	/*
    	* Perform Fluent Function call.
    	*
    	* returns: FuncResult
    	*/
    		FuncResult invoke(FuncParam param) {
    			def formDoc = new XmlDoc(param.appDoc)
    			formDoc.setText('/AvokaSmartForm/Applicant/FirstName', 'John')
    			formDoc.setText('/AvokaSmartForm/Applicant/LastName', 'Smith')
    			formDoc.setText('/AvokaSmartForm/Applicant/Email', '[email protected]')
    			formDoc.setText('/AvokaSmartForm/Applicant/Mobile', '0401010101')
    			FormFuncResult result = new FormFuncResult()
    			result.includeFormData = true
    		return result
    	}
    }
    
    Note

    We recommend writing a Groovy script in your favorite IDEA, such as Eclipse or IntelliJ, and then copy and paste it into the Groovy Script tab.

  6. Click Save to update the changes.

As you are working on the script, we recommend Creating a Groovy unit test script right away to test its implementation.

If the Groovy script uses some configurable parameters, add them in the Parameters tab. The example below shows the new three parameters: tokenTimeout, tokenLength, phoneExtractName.

The Groovy script snippet below shows how to use the new three parameters.


int tokenTimeout = inputParams.svcDef.paramsMap["tokenTimeout"]
int codeLength = inputParams.svcDef.paramsMap["tokenLength"]
String ref = (String) inputParams.svcDef.paramsMap["phoneExtractName"]
Note

The parameters’ values can be changed any time without any Groovy script modifications.

Next, learn how to configure Transact function parameters edit.