Check a Form Request IP Address

   Journey Manager (JM) The transaction engine for the platform.  |    Form Builder Platform Developer  |  All versions This feature is related to all versions.

It may be necessary in certain instances to determine the IP address of the user who has requested a form, for example, so that internal users can view a different version of a form than external users, or so that users in different countries or areas see different form content.

The form must be pre-populated with either the IP address of the requesting user, or an indicator of what type of user they are, which has been determined using the IP address in a pre-populated Groovy script.

You can do this in Manager:

  1. Create the Groovy prefill service:
    // Script parametes include: form (Form), formRequestParams (Map<String, Object>), request (HttpServletRequest), schemaSeed (Document), userAccountId (String), serviceDefinition (ServiceDefinition), serviceParameters (Map<String, String>)
    // Script return : Form XML data string value or return empty value and update the schemaSeed Document parameter
    def returnXml = '''
    <prefillData>
        <value1>''' + request.getRemoteAddr() + '''</value1>
        <value2>''' + request.getHeader("X-Forwarded-For") + '''</value2>
    </prefillData>
    ''';
    return returnXml;
  2. Create a Service Parameter containing the groovyScript. The groovyScript includes a request parameter. The request parameter is a HttpServletRequest Java object, which contains information about the request. The IP address that the request came from can be accessed using the following code:
    request.getRemoteAddr()
    Depending how the TransactionManager server is set up, this may not always give you the user’s address. For example, tm.demo.avoka.com sits behind a load balancer, which catches the user’s HTTP request and uses it to create a new one. Using the above code will return the IP address of the load balancer, rather than the user. In this instance, the user’s IP address must be accessed through the HttpServletRequest object’s header, using the code:
    request.getHeader(“X-Forwarded-For”)
  3. Create the sample input XML. In the form version data config, go to the input XML Prefill Mapping tab click Edit Input XML
  4. Create the XML Mapping. On the same tab click the Edit XML Mapping button
  5. Update the form version to include the Form Prefill Data Service.

Next, learn how to view Transact functions.