Creating a new binding using script actions / user profile

Use this forum for questions regarding adoption and functionality of OpenEMM

Moderator: moderator

ubrog
Posts: 10
Joined: Thu Jul 26, 2012 4:49 pm

Creating a new binding using script actions / user profile

Post by ubrog »

Hello,

I'm trying to create a profile page where users can edit their preferences, including subscriptions to multiple mailing lists. We have a normal double-opt-in process for the user to subscribe to one of the mailing lists. In the profile, they should be able to select more mailing lists and save that preference.

Form:
Image

There will be two cases to subscribe the user to one of the lists:
  • The user has already subscribed to the list before, so there is a binding in the database that we can update (this part works fine)
  • The user has never been subscribed to the list. We have to create a new binding in the database (that doesn't work. why?)
I came up with some code that should accomplish just that, but insertNewBindingInDB always returns false and the user is not subscribed. I'm not sure why. Can someone help me with that?`

This is my Script:

Code: Select all

## Mailing List 187
#if ($requestParameters.LIST01ID)
  #set( $list01 = $requestParameters.LIST01 )
  $BindingEntry.setMailinglistID( 187 ) )
  $BindingEntry.setCustomerID($customerID)

  #if($list01)
    ## get the binding from DB and check if successful
    #if($BindingEntry.getUserBindingFromDB(1) == true))
      ## if the user has activated list01
      #if($list01 == 1)
        ## subscribe the user
        $BindingEntry.setUserStatus(0)
        $BindingEntry.updateBindingInDB(1)
      #else
        ## unsubscribe the user
        $BindingEntry.setUserStatus(0)
        $BindingEntry.updateBindingInDB(1)
      #end 
    
    ## There is no binding in the database yet
    #else
      #if($list01 == 1)
        # create a new binding
        $BindingEntry.setMailinglistID( 187 ) )
        $BindingEntry.setCustomerID($customerID)
        $BindingEntry.setUserType("W")
        $BindingEntry.setUserStatus(1)
        $BindingEntry.setUserRemark("added in profile")
        $BindingEntry.setExitMailingID(0)
        $BindingEntry.setMediaType(0)
        
        #set ($res = $BindingEntry.insertNewBindingInDB(1))
      #end
    #end
  #end
#end
ubrog
Posts: 10
Joined: Thu Jul 26, 2012 4:49 pm

Re: Creating a new binding using script actions / user profi

Post by ubrog »

I.... I don't know what happened, but maybe I had some invalid bindings in the database from previous tries. I cleaned that out and now it works!

I hope I didn't waste anyones time. I'l leave the post up in case someone can use the code.
maschoff
Site Admin
Posts: 2608
Joined: Thu Aug 03, 2006 10:20 am
Location: Munich, Germany
Contact:

Re: Creating a new binding using script actions / user profi

Post by maschoff »

You did not waste anyone's time because you answered your own question too quickly for us. :-)

Anyway, thanks for sharing your code.
OpenEMM Maintainer
Post Reply