Page 1 of 1
Preventing an email update?
Posted: Thu Feb 21, 2013 2:29 am
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
Re: Preventing an email update?
Posted: Fri Feb 22, 2013 2:29 pm
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.
Re: Preventing an email update?
Posted: Fri Feb 22, 2013 7:45 pm
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

Re: Preventing an email update?
Posted: Mon Feb 25, 2013 5:33 pm
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.
Re: Preventing an email update?
Posted: Tue Feb 26, 2013 8:20 am
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.
Re: Preventing an email update?
Posted: Tue Feb 26, 2013 8:27 am
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
Re: Preventing an email update?
Posted: Wed Feb 27, 2013 2:36 pm
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 :
to
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
Re: Preventing an email update?
Posted: Wed Feb 27, 2013 2:48 pm
by maschoff
Thanks for sharing your findings!
Re: Preventing an email update?
Posted: Wed Feb 27, 2013 2:58 pm
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.
Re: Preventing an email update?
Posted: Wed Feb 27, 2013 3:09 pm
by maschoff
BTW, did you implement the bugfix linked above (replacing one line of code in class ExecuteScript)?
Re: Preventing an email update?
Posted: Wed Feb 27, 2013 3:17 pm
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.
Re: Preventing an email update?
Posted: Wed Feb 27, 2013 3:24 pm
by maschoff
OK, so apparently you are not affected by this bug.
Re: Preventing an email update?
Posted: Thu Feb 28, 2013 3:41 pm
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.
Re: Preventing an email update?
Posted: Thu Feb 28, 2013 4:42 pm
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.
Re: Preventing an email update?
Posted: Thu Feb 28, 2013 5:23 pm
by maschoff
My hunch: Defining $Int as integer, converting $id to an integer and assigning it to $customerID (to remove leading zeros?)