Retrieving mailinglistname in form

Use this forum for questions regarding adoption and functionality of OpenEMM

Moderator: moderator

diax
Posts: 6
Joined: Mon Aug 03, 2009 9:30 am

Retrieving mailinglistname in form

Post by diax »

Hi all.

First of all, we're running OpenEMM 5.5.1 on a windows box and we like it very much :) , good job OpenEMM-Team!


I'm currently creating one unsubscribe-Form for all Mailinglists. So for every Mailinglist, we wanna use the same Form. (Not one form to unsubscribe from all mailinglists in one step). So far it works pretty well.

My Problem:
I'd like to display the Name of the Mailinglist that the user is about to unsubscribe from. Is there a way to retrieve this data, like with $customer.<customer_attributes>?

Many thanks in advance
maschoff
Site Admin
Posts: 2628
Joined: Thu Aug 03, 2006 10:20 am
Location: Munich, Germany
Contact:

Post by maschoff »

The mailinglist ID is included in the UID but there is no way to decode it (only via webservice).
OpenEMM Maintainer
diax
Posts: 6
Joined: Mon Aug 03, 2009 9:30 am

Post by diax »

Hi ma,

thanks for your answer.

To all who suffer under the same problem:

I finally found a way to retrieve the data i needed.
Thx to the almighty ScriptHelper-Object :)

First i had to add the Mailing-ID to the unsub-link:

Code: Select all

  http://myopenemmserver.com:8080/form.do?agnCI=1&agnFN=my_unsub_form&agnUID=##AGNUID##&mi=##MAILING_ID##
Note the appended mi-Parameter, it will be used in the script below!

Then I've created an action, used as initial action for my
unsub-form, consisting of two steps:

1. Load recipient-data
Load even if customer is not a active subscriber (not checked)

2. Script-Action

Code: Select all

## Set company-ID (could also be retrieved from requestParameters)
#set( $company_id = 1 )

## Get the mailing-ID which we set in the mailings unsubscribe URL
#set( $mail_id = $requestParameters.mi )

#if( $mail_id )
  ## Requestparameters seem to be strings, so we need an integer for casting
  #set( $Integer = 0 )
  #set( $mail_id_int  = $Integer.parseInt($mail_id) )

  #if( $mail_id_int )
    ## Using the MailingDao we instantiate a mailingbean
    #set( $mailing = $MailingDao.getMailing($mail_id_int, $company_id) )

    #if( $mailing )
      ## Now we can retrieve the mailinglist-ID
      #set( $mail_list_id = $mailing.getMailinglistID() )

      #if( $mail_list_id )
        ## Using the ScriptHelper-object, we instantiate an ApplicationContext-object
        #set( $app_context = $ScriptHelper.getApplicationContext() )
        
        #if( $app_context )
          ## With it we can instantiate (any Bean/Dao, especially a) mailinglistbean 
          #set( $mailing_list = $app_context.getBean("MailinglistDao").getMailinglist($mail_list_id, $company_id) )

          #if( $mailing_list )
            ## Finally we can retrieve the shortname of the mailing_list
            #set( $mailing_list_name = $mailing_list.getShortname() )
          #end
        #end 
      #end 
    #end
  #end
#end

## This seems to be mandatory for a script not to result in an error
#set( $scriptResult="1" )

Now i can use the Mailinglist-Name in the unsub form:

Code: Select all

Click below to unsub from Mailinglist <strong>$!mailing_list_name</strong>!
The big (and ugly) if-triangle in combination with
quiet reference (the ! in front of 'mailing_list_name'-variable) make sure,
that the mailing_list_name will only appear, if a mi-Parameter is passed via
unsub-URL:

I.E.
http://myopenemmserver.com:8080/form.do ... gnUID&mi=5
will -assumed Mailinglist "FancyStuff4U" has ID 5- result in
Click below to unsub from Mailinglist FancyStuff4U!

http://myopenemmserver.com:8080/form.do ... someAgnUID
will result in
Click below to unsub from Mailinglist !

http://myopenemmserver.com:8080/form.do ... &mi=foobar
will result in the error template.


I hope, my solution-post can help other OpenEMM-Users.


Have Fun and happy OpenEMM'ing
-diax
maschoff
Site Admin
Posts: 2628
Joined: Thu Aug 03, 2006 10:20 am
Location: Munich, Germany
Contact:

Post by maschoff »

I am honestly impressed!
OpenEMM Maintainer
diax
Posts: 6
Joined: Mon Aug 03, 2009 9:30 am

Post by diax »

I'm flattered! :)
Post Reply