Preventing an email update?

Use this forum for questions regarding adoption and functionality of OpenEMM

Moderator: moderator

cedric
Posts: 9
Joined: Thu Feb 14, 2013 11:44 am

Preventing an email update?

Post by cedric »

Hello,

First of all I apologize if the answer has already been given somewhere in the forum.

I'm using OpenEMM 2011 and I wanted to know if there was a way to prevent the update of a profile if the email supplied in the profile form is already used in the database.
Maybe using actions script but I do not really know how.

Could you give me a hint?

Thanks
maschoff
Site Admin
Posts: 2608
Joined: Thu Aug 03, 2006 10:20 am
Location: Munich, Germany
Contact:

Re: Preventing an email update?

Post by maschoff »

Do you mean that you want to prevent a user changing his/her email address in the profile page shown after clicking on a profile link? If so, display the address field as read-only.
OpenEMM Maintainer
cedric
Posts: 9
Joined: Thu Feb 14, 2013 11:44 am

Re: Preventing an email update?

Post by cedric »

No, that's not what I meant.

Let's say we have a profile form and the user want to change his/her email address. Is it possible, problably with action scripts - correct me if I'm wrong, to check if the new email address is already registered in the database and if it does to return the form error?

In the action script documentation, there is a script that is meant to load all customer data for a given email address :

Code: Select all

$Customer.loadCustDBStructure()
$Customer.resetCustParameters()
$Customer.setCustomerID(0)
#set(customerID=$Customer.findByKeyColumn("EMAIL", $email))
#set($requestParameters = $ScriptHelper.newHashMap().putAll($Customer.getCustomerDataFromDb()))
#set($scriptResult="1")
It sounds like a good start to work with but the script in the example is not working :?
cedric
Posts: 9
Joined: Thu Feb 14, 2013 11:44 am

Re: Preventing an email update?

Post by cedric »

I've tried with this script action with no avail :

Code: Select all

#set($email = $requestParameters.EMAIL)
#set($check = $Customer.findByKeyColumn("EMAIL", $email))
#if($check == "0")
  #set($scriptResult = "1")
#else
  #set($scriptResult = "0")
#end
No matter what if the email address is already registered or not, I get my error form.
maschoff
Site Admin
Posts: 2608
Joined: Thu Aug 03, 2006 10:20 am
Location: Munich, Germany
Contact:

Re: Preventing an email update?

Post by maschoff »

We might have a bug in the velocity script handling. Please have a look at this thread:

https://forum.openemm.org/post7875.html#p7875

If you are interested I could mail you a class file for replacement so that you can check if the changed version works for you.
OpenEMM Maintainer
maschoff
Site Admin
Posts: 2608
Joined: Thu Aug 03, 2006 10:20 am
Location: Munich, Germany
Contact:

Re: Preventing an email update?

Post by maschoff »

Here a general code input:

Code: Select all

## check, if an email address exists:
#set($customerID=$Customer.findByKeyColumn("EMAIL", $email))

## do something if the address exists (like change to profile or setting a binding)
#if($customerID != 0)
# ...
## do something if the address does not exist (like creating a new record and setting a binding
#else
# ...
#end
OpenEMM Maintainer
cedric
Posts: 9
Joined: Thu Feb 14, 2013 11:44 am

Re: Preventing an email update?

Post by cedric »

Thanks for the anwser especially the one referring to the post on the forum.

After taking a look in the velocity log, i saw where the problem was :

Code: Select all

2013-02-27 11:51:39,263 - Error in evaluation of == expression. Both arguments must be of the same Class. Currently left = class java.lang.Integer, right = class java.lang.String. null [line 3, column 14] (ASTEQNode)
I changes this line in my action script :

Code: Select all

#if($check == "0")
to

Code: Select all

#if("$check" == "0")
Finally here is how I did to avoid an email update/subscription if the email address provided is already in the database :

For subscription I'm using this script followed by a subscribe action :

Code: Select all

#set($email = $requestParameters.EMAIL)
#set($check = $Customer.findByKeyColumn("EMAIL", $email))
#if("$check" == "0")
  #set($scriptResult = "1")
#else
  #set($scriptResult = "0")
#end
For profile update I'm using gthis script followed by a subscribe action :

Code: Select all

#set($id = $requestParameters.CUSTOMERID)
#set($email = $requestParameters.EMAIL)
#set($check = $Customer.findByKeyColumn("EMAIL", $email))
#if("$check" == "$id" || "$check" == "0")
  #set($scriptResult = "1")
#else
  #set($scriptResult = "0")
#end
With this code in my profile update form in :

Code: Select all

<input type="hidden" name="CUSTOMERID" value="$customerID" />
EDIT : added a logical OR in the update script action
Last edited by cedric on Wed Feb 27, 2013 2:53 pm, edited 2 times in total.
maschoff
Site Admin
Posts: 2608
Joined: Thu Aug 03, 2006 10:20 am
Location: Munich, Germany
Contact:

Re: Preventing an email update?

Post by maschoff »

Thanks for sharing your findings!
OpenEMM Maintainer
cedric
Posts: 9
Joined: Thu Feb 14, 2013 11:44 am

Re: Preventing an email update?

Post by cedric »

You're welcome! Thanks you for the wonderful tool OpenEMM is :)

By the way, my update action script is not really efficient (because I use a subscribe action after) : it creates a new recipient in the database instead of updating the old one.
As soon as I manage to get over this I'll post a solution.
maschoff
Site Admin
Posts: 2608
Joined: Thu Aug 03, 2006 10:20 am
Location: Munich, Germany
Contact:

Re: Preventing an email update?

Post by maschoff »

BTW, did you implement the bugfix linked above (replacing one line of code in class ExecuteScript)?
OpenEMM Maintainer
cedric
Posts: 9
Joined: Thu Feb 14, 2013 11:44 am

Re: Preventing an email update?

Post by cedric »

No, I didn't. (I don't even know how to do so...)
This post only gave me the idea to look in the velocity log.
maschoff
Site Admin
Posts: 2608
Joined: Thu Aug 03, 2006 10:20 am
Location: Munich, Germany
Contact:

Re: Preventing an email update?

Post by maschoff »

OK, so apparently you are not affected by this bug.
OpenEMM Maintainer
cedric
Posts: 9
Joined: Thu Feb 14, 2013 11:44 am

Re: Preventing an email update?

Post by cedric »

Hi maschoff,

I'm still having issues but only if the profile is updated with a new email address.

Here is my action script that almost works as I want it to :

Code: Select all

#set($id = $requestParameters.CUSTOMERID)
#set($email = $requestParameters.EMAIL)
#set($check = $Customer.findByKeyColumn("EMAIL", $email))
#if("$check" == "$id" || "$check" == "0")
  $Customer.setCustomerID($id)
  $Customer.importRequestParameters($requestParameters, null)
  $Customer.updateInDB()
  #set($scriptResult = "1")
#else
  #set($scriptResult = "0")
#end
First, I have this error in the velocity log :

Code: Select all

2013-02-28 15:26:37,629 - org.apache.velocity.runtime.exception.ReferenceException: reference : template = null [line 5,column 3] : $Customer.setCustomerID($id) is not a valid reference.
Furthermore, I can update any fields in the customer profile but when a new email address is entered (which is not in the database) it's creating a new customer profile instead of updating the profile.

Finally, I also need to handle mailinglist bindings within my script. Any hints? (we have 2 differents mailing-lists)

Thanks.

PS : If you need more info about forms used etc, just let me know.
cedric
Posts: 9
Joined: Thu Feb 14, 2013 11:44 am

Re: Preventing an email update?

Post by cedric »

Well after digging the internet I came out with this action script :

Code: Select all

#set($id = $requestParameters.CUSTOMERID)
#set($Int = 0)
#set($customerID = $Int.parseInt($id))
#set($email = $requestParameters.EMAIL)
#set($check = $Customer.findByKeyColumn("EMAIL", $email))
#if("$check" == "$id" || "$check" == "0")
  $Customer.setCustomerID($customerID)
  $Customer.importRequestParameters($requestParameters, null)
  $Customer.updateInDB()
  #if($requestParameters.agnSUBSCRIBE1 == "0")
    $BindingEntry.setMailinglistID(3)
    $BindingEntry.setCustomerID($customerID)
    $BindingEntry.setUserStatus(4)
    $BindingEntry.setUserRemark("Opt-out by User")
    $BindingEntry.updateStatusInDB(1)
  #else
    $BindingEntry.setMailinglistID(1)
    $BindingEntry.setCustomerID($customerID)
    $BindingEntry.setUserStatus(1)
    $BindingEntry.setUserRemark("Opt-in by User")
    $BindingEntry.updateStatusInDB(1)
  #end
  #if($requestParameters.agnSUBSCRIBE2 == "0")
    $BindingEntry.setMailinglistID(2)
    $BindingEntry.setCustomerID($customerID)
    $BindingEntry.setUserStatus(4)
    $BindingEntry.setUserRemark("Opt-out by User")
    $BindingEntry.updateStatusInDB(1)
  #else
    $BindingEntry.setMailinglistID(8)
    ##$BindingEntry.setCustomerID($customerID)
    $BindingEntry.setUserStatus(1)
    $BindingEntry.setUserRemark("Opt-in by User")
    $BindingEntry.updateStatusInDB(1)
  #end
  #set($scriptResult = "1")
#else
  #set($scriptResult = "0")
#end
Not sure of what

Code: Select all

#set($Int = 0)
#set($customerID = $Int.parseInt($id))
is actually doing but it fixed my problem.
maschoff
Site Admin
Posts: 2608
Joined: Thu Aug 03, 2006 10:20 am
Location: Munich, Germany
Contact:

Re: Preventing an email update?

Post by maschoff »

My hunch: Defining $Int as integer, converting $id to an integer and assigning it to $customerID (to remove leading zeros?)
OpenEMM Maintainer
Post Reply