• 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 Version Selector

The Form Version Selector service is used to select the version of a form to render when a user starts accessing the form.
For simple purposes, the current version of a form can be used; or for example in A/B testing, a version of the form may be selected either completely at random or depending on certain characteristics of the user.

This service is configured via the form version "Services" tab.

Service Invoke Parameters

Parameter Description Nullable
svcDef the service definition value object, see SvcDef no
form the form value object, see Form no
request the servlet HttpServletRequest no
user the authenticated user, see User yes

Script Result

The script can return String object:

  • if the returned object is null, then the current template version will be resolved,
  • otherwise the returned String object will be resolved to the selected template version.

Examples

Region Form Version Selection

The example below chooses a region form version.

import com.avoka.core.groovy.GroovyLogger as logger
import com.avoka.tm.vo.*
import javax.servlet.http.*

class FluentFormVersionSelector {

    /*
     * Perform form version selector service
     */
    String invoke(SvcDef svcDef, Form form, HttpServletRequest request, User user) {
    
        String country = request.getParameter('country')
        
        if ('AU'.equals(country)) {
            return '1.0'
        }
        
        if ('DE'.equals(country)) {
            return '2.0'
        }
               
        if ('JP'.equals(country)) {
            return '3.0'
        }
        
        return null        
    }
}

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.vo.*
import org.junit.Test

class UnitTest extends AbstractJUnitTest {

    /*
     * Perform service unit test
     *
     * throws: exception if unit test fails
     */
    @Test
    void testVersionAU() throws Exception {

        Form form = new MockVoBuilder().createForm()
        MockRequest request = new MockRequest()
        request.setParameter('country','AU')

        Map params = [
            "svcDef": svcDef,
            "form": form,            
            "request": request,
            "user": null
        ]

        try {
            String result = new ServiceInvoker(svcDef).invoke(params)
            
            assert result == '1.0'

        } catch (Exception re) {
            assert false : 'Test failed'
        }
    }
}
← Delivery FunctionForm Security Filter →

Terms & Conditions

Privacy Policy

Cookie Policy

Copyright © 2003-2022 Temenos Headquarters SA