Preventing an email update?
Moderator: moderator
Preventing an email update?
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
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
-
- Site Admin
- Posts: 2628
- Joined: Thu Aug 03, 2006 10:20 am
- Location: Munich, Germany
- Contact:
Re: Preventing an email update?
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
Re: Preventing an email update?
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 :
It sounds like a good start to work with but the script in the example is not working 
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")

Re: Preventing an email update?
I've tried with this script action with no avail :
No matter what if the email address is already registered or not, I get my error form.
Code: Select all
#set($email = $requestParameters.EMAIL)
#set($check = $Customer.findByKeyColumn("EMAIL", $email))
#if($check == "0")
#set($scriptResult = "1")
#else
#set($scriptResult = "0")
#end
-
- Site Admin
- Posts: 2628
- Joined: Thu Aug 03, 2006 10:20 am
- Location: Munich, Germany
- Contact:
Re: Preventing an email update?
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.
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
-
- Site Admin
- Posts: 2628
- Joined: Thu Aug 03, 2006 10:20 am
- Location: Munich, Germany
- Contact:
Re: Preventing an email update?
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
Re: Preventing an email update?
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 :
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 :
For profile update I'm using gthis script followed by a subscribe action :
With this code in my profile update form in :
EDIT : added a logical OR in the update script action
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)
Code: Select all
#if($check == "0")
Code: Select all
#if("$check" == "0")
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
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
Code: Select all
<input type="hidden" name="CUSTOMERID" value="$customerID" />
Last edited by cedric on Wed Feb 27, 2013 2:53 pm, edited 2 times in total.
Re: Preventing an email update?
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.

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.
-
- Site Admin
- Posts: 2628
- Joined: Thu Aug 03, 2006 10:20 am
- Location: Munich, Germany
- Contact:
Re: Preventing an email update?
BTW, did you implement the bugfix linked above (replacing one line of code in class ExecuteScript)?
OpenEMM Maintainer
Re: Preventing an email update?
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.
This post only gave me the idea to look in the velocity log.
-
- Site Admin
- Posts: 2628
- Joined: Thu Aug 03, 2006 10:20 am
- Location: Munich, Germany
- Contact:
Re: Preventing an email update?
OK, so apparently you are not affected by this bug.
OpenEMM Maintainer
Re: Preventing an email update?
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 :
First, I have this error in the velocity log :
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.
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
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.
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?
Well after digging the internet I came out with this action script :
Not sure of what is actually doing but it fixed my problem.
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
Code: Select all
#set($Int = 0)
#set($customerID = $Int.parseInt($id))
-
- Site Admin
- Posts: 2628
- Joined: Thu Aug 03, 2006 10:20 am
- Location: Munich, Germany
- Contact:
Re: Preventing an email update?
My hunch: Defining $Int as integer, converting $id to an integer and assigning it to $customerID (to remove leading zeros?)
OpenEMM Maintainer