• Platform
    • Manager
    • Maestro
    • Exchange
    • Workspaces
    • Analytics
    • Springboard
    • API
Transact Services Guide (TSG)

Transact Services Guide (TSG)

  • Getting Started
  • Groovy Guide
  • Service Development
  • Groovy Services API
  • REST API

›Groovy Services API

Getting Started

  • Introduction

Groovy Guide

  • Groovy Guide
  • Groovy Declarations
  • Control Statements

Service Development

  • Service Development
  • Transaction Processing Sequence
  • Service Logging
  • Remote Service Calls
  • Fluent Security Configuration
  • Third-party Libraries

Groovy Services API

  • Groovy Services API
  • Fluent Function
  • Delivery Function
  • Form Version Selector
  • Form Security Filter
  • Form Prefill
  • Tracking Number
  • Form Dynamic Data
  • Submission Preprocessor
  • Receipt Number
  • Form Saved Processor
  • Submission Data Validator
  • Submission Completed Processor
  • Render Receipt Service
  • Delivery Process
  • Task Expiry Process
  • Email Service
  • Job Action
  • Scheduled Service
  • Groovy Service
  • SSO Revalidation
  • SSO Get Authentication Token
  • SSO Authentication OK Response
  • SSO Authentication Provider
  • Transaction History Publisher
  • Virus Scan

REST API

  • REST API
  • REST Application Package API
  • REST Delivery API
  • REST Form Groups API
  • REST Groovy Service Invoke v2
  • REST Service Definitions API
  • REST Tasks API
  • REST TestCenter API
  • REST TPac API
  • REST Transactions API
  • REST Transaction History API

Workspaces API

  • Workspaces API
  • Filters
  • Sort
  • Workspaces Category API
  • Workspaces Current User API
  • Workspaces Extract Name API
  • Workspaces Form API
  • Workspaces Group API
  • Workspaces Job API
  • Workspaces Org API
  • Workspaces Property Name API
  • Workspaces Space API
  • Workspaces Txn API
  • Workspaces User API

Form Prefill

The Form Prefill service is used provide XML pre-population data to the form when it is first rendered. Please note this service is not called when someone subsequently opens a saved form.

Service Invoke Parameters

Parameter Description Nullable
svcDef the service definition value object, see SvcDef no
form the form value object, see Form no
formXml the XML Document object which is used to pre-fill the form with no
txn the transaction record value object, see Txn yes
request the servlet HttpServletRequest yes
user the authenticated user, see User yes

Script Result

The script can either return a form XML string value or update the schemaSeed XML Document parameter object. If the script returns an XML data then this value will be either:

  • used as the form's XML data Document, when no Input XML Prefill Mapping are configured
  • used as input XML prefill data which will be mapped into the forms XML data Document, if Input XML Prefill Mapping are configured

If the script does not return any XML or update the schemaSeed XML Document parameter, then the form will use its default prefill data instead.

Error Handling

If your Groovy script throws an error when executing the exception will be logged to the Journey Manager database error log and the user will be redirected to a form error page which will contain a Error Reference Number. This reference number is the Journey Manager database error log ID which you can use to look up the error. The error log record will contain useful contextual information about the error.

If, at prefill time, you determine you don't want the user to view the form you can redirect away to another page using a RedirectException.

import com.avoka.tm.util.RedirectException

throw new RedirectException('/form-expired.htm?formCode=' + form.formCode)

Please note in TransactField App you cannot use this design pattern, as the Form Prefill Service is executed on the server and not in the client.

Service Template

This section shows service template Groovy script.

import com.avoka.core.groovy.GroovyLogger as logger
import com.avoka.tm.util.*
import com.avoka.tm.vo.*
import javax.servlet.http.*
import org.w3c.dom.*

class FluentFormPrefill {

    /*
     * Perform form prefill service
     *
     * return: the form XML prefill document
     * throws: RedirectException to redirect user to another page
     */
    Document invoke(SvcDef svcDef, Form form, Document formXml, Txn txn, HttpServletRequest request, User user) throws RedirectException {

        // TODO: replace with data lookup call

        XmlDoc xmlDoc = new XmlDoc(formXml)

        xmlDoc.setText("/AvokaSmartForm/Customer/Address/PostCode", "9999")

        return xmlDoc.document
    }
}

Unit Test Template

This section shows unit test template Groovy script.

import com.avoka.core.groovy.GroovyLogger as logger
import com.avoka.tm.svc.*
import com.avoka.tm.test.*
import com.avoka.tm.util.*
import com.avoka.tm.vo.*
import org.w3c.dom.*
import org.junit.Test

class UnitTest extends AbstractJUnitTest {

    /*
     * Perform service unit test
     *
     * throws exception if unit test fails
     */
    @Test
    void testPrefillPostCode() throws Exception {
    
        Document formXml = new XmlDoc(testParams['Test XML Data']).document
        MockRequest request = new MockRequest()
        
        Map params = [
            "svcDef": svcDef,
            "form": null,
            "formXml": formXml,
            "txn": null,
            "request": request,
            "user": null
        ]

        Document result = (Document) new ServiceInvoker(svcDef).invoke(params)

        assert result != null

        Path path = new Path(result)

        assert "9999" == path.val("//Customer/Address/PostCode")
    }
}
← Form Security FilterTracking Number →

Terms & Conditions

Privacy Policy

Cookie Policy

Copyright © 2003-2022 Temenos Headquarters SA