Skip to content

1.3 Examples

Below are some examples that can be realized with Velocity Script.

1.3.1 Unsubscribe script automatically via all mailing lists

Usage: This script allows a recipient to unsubscribe from all active mailing lists with one click.

The record is identified based on the e-mail address. Subsequently, all bindings (memberships to mailing lists) of the data set are loaded and checked for which binding a UserStatus 1 (= active) is determined. In this case the dataset is unsubscribed for this mailing list, new status of the dataset is 3.

By using loadAllListBindings, even mailing lists which do not exist at the time of script creation will be considered in the future!

In the script, the corresponding CompanyID must be entered in the marked line.

#set($customerID=$Customer.findByKeyColumn("EMAIL",
$requestParameters.EMAIL.toLowerCase()))
#set($company_id = <cid>)
#if($customerID!=0) #set($allMailingLists=$Customer.loadAllListBindings())
#foreach($mailingList in $allMailingLists)
#foreach($list in $mailingList)
#set($mlist="$list.getMailinglistID()")
#set($int_mlist=$ScriptHelper.parseInt($mlist))
$BindingEntry.setMailinglistID($int_mlist)
$BindingEntry.setCustomerID($customerID)
#if($BindingEntry.getUserBindingFromDB($company_id) == true)
#if($BindingEntry.getUserStatus() == 1)
$BindingEntry.setUserStatus(4)
$BindingEntry.setUserRemark("Opt-out
by User")
$BindingEntry.updateStatusInDB($company_id) #end
#end
#end
#end
#end

1.3.2 Activation of the user status on several defined mailing lists

Usage: This script allows a recipient to confirm the double opt-in for multiple mailing lists with one click.

Based on the e-mail address, the system checks whether a CustomerID exists for the record. If a CustomerID can be determined, a value greater than 0 is output. Then the bindings (memberships to mailing lists) of the data record are loaded to the listed mailing lists (line 5) and checked whether the status "Waiting for confirmation" (= 5) exists.

If a hit for the CustomerID is found on one of the mailing lists listed, the status is changed from 5 to 1 (= active). If the status differs from 5, nothing changes for the record on the respective mailing list.

In the script, the corresponding CompanyID and the desired mailing list IDs must be entered in the marked lines.

#set($customerID = $Customer.findByKeyColumn("EMAIL",
$requestParameters.EMAIL))
#set($lang = $requestParameters.language)
#set($companyID = <cid>)
#set($allMailingLists = [<ml1_id>,<ml2_id>,<ml3_id>,<ml4_id>])
#if($customerID!=0)
    $Customer.setCustomerID($customerID)
    $Customer.setCompanyID($companyID)
    $Customer.loadCustDBStructure()
    $Customer.importRequestParameters($requestParameters, null);
    $Customer.updateInDB();
    #foreach($mailingList in $allMailingLists)
        $BindingEntry.setMailinglistID($mailingList)
        $BindingEntry.setCustomerID($customerID)
        #if($BindingEntry.getUserBindingFromDB($companyID) == true)
            #if($BindingEntry.getUserStatus() == 5)
                $BindingEntry.setUserStatus(1)
                $BindingEntry.setUserRemark("Opt-in by User")
                $BindingEntry.updateStatusInDB($companyID)
            #end
        #end
    #end
#end
#set($scriptResult = "1")

1.3.3 Sending the last newsletter sent

(getLastSentWorldMailingIDByCompanyAndMailinglist)

Usage: With this script you can send a recipient the last sent newsletter for the respective mailing list directly after confirming the double opt-in (by clicking on the activation link).

Usually, clicking on the activation link leads to an E-Marketing Manager welcome page. An action is assigned to this page, which has the following structure (define under Trigger Management)

Step 1: „Double opt-in confirmation“, to activate the recipient on the mailing list (User Status = 1)

Step 2: „Load recipient data“ – this will load the data of the record, in the following script we only need the $customerID

Step 3: „Script-action“, with the following velocity script (only <cid> for the Company_ID and <ml_id> for the Mailinglist_ID need to be adjusted):

## Set parameters ( e.g. $companyID = 15 )
#set($companyID = <cid>)
#set($mailingListID = <ml_id>)

## Determine last sent mailing 
#set($lastSentMailingID=$ScriptHelper.getLastSentWorldMailingIDB yCompanyAndMailinglist($companyID, $mailingListID))

## Send newsletter 
#set($mailing=$MailingDao.getMailing($lastSentMailingID,
$companyID))
## customerID aus "Load recipient data"
$ScriptHelper.sendEventMailing($mailing, $customerID, 0, "1", null)

#set($scriptResult="1")

1.3.4 Checking the status on registration

Usage: This describes the possibility of rejecting a recipient if an active binding exists, or informing them of the status.

The registration page (e.g. DOI-1) sends the form data to the confirm form (e.g. DOI-2). With the DOI-2, a initial script action is now created:

Step 1: Script action (velocity script with the necessary "switch")

## Determine whether a "Customer_ID" based on the e-mail already exists
#set($customerID = $Customer.findByKeyColumn("EMAIL",
$requestParameters.email))

## The parameters for CompanyID and mailing list should be taken from the request.
#set($ci = $ScriptHelper.parseInt($!requestParameters.agnCI))
#set($mid =
$ScriptHelper.parseInt($!requestParameters.agnMAILINGLIST))
## The form call is set to successful by default
#set($scriptResult = "1")

#if($customerID != 0)
$BindingEntry.setMailinglistID($mid)
$BindingEntry.setCustomerID($customerID)

   ## a record was found, a binding check follows
   #if($BindingEntry.getUserBindingFromDB($ci) == true)

        ## a binding was found, the system checks for status 1 = active
        #if($BindingEntry.getUserStatus() == 1)

           ## the registration is cancelled, the error page should be displayed
           #set($scriptResult = "0")
           #set($status = " You are already subscribed!")
        #end

        ## checking for status 3 = opt-out by user
        #if($BindingEntry.getUserStatus() == 3)

           ## the registration is continued
           #set($scriptResult = "0")
        #end
   #end
#end

Step 2: Add / update records (preferably with matching of duplicates and Double Opt-in)

Step 3: Send action-based mailing (for verification of the DOI by the address owner) On the error page, the status information can now be inserted in the HTML code:

<p> The registration could not be continued. <br />
Reason: $status</p>