Action to update user field

Use this forum for questions regarding adoption and functionality of OpenEMM

Moderator: moderator

bartgras
Posts: 2
Joined: Wed Apr 03, 2013 2:56 am

Action to update user field

Post by bartgras »

Hi,

I wanted to simplify a bit profile update implemented in OpenEMM, basically I don't want to add new columns in database each time I want to track users' clicks.
That's why I'm trying to implement general action that would update user's profile once he clicks on a link.
Let's say the field is called "clicks" and is anchored to all buttons in all mailings. If user clicks on any link in newsletter than script adds string " <date> <mailing number> <button> |".
So, for example if user clicked 3 times in 3 separate mailings (with IDs 3,5 and 7) than field "clicks" would have following data "2013-03-03 3 BTN3 | 2013-03-20 5 BTN2 | 2013-04-02 7 BTN8 |"

So far, in my action, I'm trying to read user data, modify any field and save it back to database. Below action loads user's profile and tries to modify field "lastname".

Code: Select all

$ScriptHelper.println("---------------START----------------")

$Customer.resetCustParameters()
$Customer.setCustomerID($customerID)
$Customer.setCompanyID(1)

$Customer.loadCustDBStructure()
$Customer.loadAllBindings()
#set($requestParameters=$Customer.getCustomerDataFromDb())

$ScriptHelper.println($requestParameters.lastname.toString())
$requestParameters.put("lastname", "MODIFIED LASTNAME")
$ScriptHelper.println($requestParameters.lastname.toString())

#if($Customer.importRequestParameters($requestParameters, null))
    $ScriptHelper.println("requestParameters SUCCESS")
#else
    $ScriptHelper.println("requestParameters FALSE")
#end

$ScriptHelper.println("$CustomerID | $CompanyID | $requestParameters")
#if($Customer.updateInDB())
    $ScriptHelper.println("Customer update SUCCESS")
    $ScriptHelper.println($Customer.lastname.toString())
#else
    $ScriptHelper.println("Customer update FALSE")
    $ScriptHelper.println($Customer.getCustomerDataFromDb().lastname)
#end

$ScriptHelper.println($Customer.getCustomerDataFromDb().lastname)

$ScriptHelper.println("-----END------")

#set($scriptResult="1")
It's almost working - It modifies $Customer but method $Customer.updateInDB() doesn't update profile in database (but as you can see in logs below method returns "True" and $Customer.lastname.toString() is set to new value)

In documentation, for method $Customer.updateInDB() it's written "Set the following parameters before calling this method: CustomerID, CompanyID (EMM only) and import $requestParameters"
and I think I did set them properly.

Here is what I get in openemm_core.log:

Code: Select all

2013-04-03 10:05:50,098: ERROR [http-8080-11] org.agnitas.util.ScriptHelper - ---------------START----------------
2013-04-03 10:05:50,126: ERROR [http-8080-11] org.agnitas.util.ScriptHelper - OldName
2013-04-03 10:05:50,126: ERROR [http-8080-11] org.agnitas.util.ScriptHelper - MODIFIED LASTNAME
2013-04-03 10:05:50,127: ERROR [http-8080-11] org.agnitas.util.ScriptHelper - requestParameters SUCCESS
2013-04-03 10:05:50,127: ERROR [http-8080-11] org.agnitas.util.ScriptHelper - 46697 | 1 | {lastname=MODIFIED LASTNAME, creation_date_second_date=37, change_date_day_date=2, creation_date=2013-03-27 18:08:37, title=, change_date_minute_date=23, creation_date_month_date=3, creation_date_day_date=27, change_date_second_date=58, creation_date_hour_date=18, creation_date_year_date=2013, change_date=2013-04-02 10:23:58, firstname=Tom, change_date_year_date=2013, change_date_hour_date=10, datasource_id=12, mailtype=1, email=email@company.com, creation_date_minute_date=8, change_date_month_date=4, customer_id=46697}
2013-04-03 10:05:50,127: ERROR [http-8080-11] org.agnitas.util.ScriptHelper - Customer update SUCCESS
2013-04-03 10:05:50,127: ERROR [http-8080-11] org.agnitas.util.ScriptHelper - MODIFIED LASTNAME
2013-04-03 10:05:50,129: ERROR [http-8080-11] org.agnitas.util.ScriptHelper - OldName
2013-04-03 10:05:50,129: ERROR [http-8080-11] org.agnitas.util.ScriptHelper - -----END------
I've been trying many versions of this script and none seem to work. I appreciate your help.
bartgras
Posts: 2
Joined: Wed Apr 03, 2013 2:56 am

Re: Action to update user field

Post by bartgras »

One more question I forgot to ask.

Looking at my "clicks" field example. Is it possible to capture button name or URL from mailing?
I've been looking at $requestParameters but it only has data like e.g. following: {uid=1.f.1015.1x.b1wj1q8med, agnQueryString=uid=1.f.1015.1x.b1wj1q8med}

Is it possible to "decode" it and read URL or any other data that would help me to identify button name?
If not - any other idea how to get button name/URL that had been clicked by user in the mailing?

Thanks for your help.
economicist
Posts: 4
Joined: Mon Oct 15, 2012 4:41 pm

Re: Action to update user field

Post by economicist »

The "uid=" field contains all of the information about a link. It's has the format: company_id.mailing_id.customer_id.url_id.signature

It may look garbled, but that's only because the base-10 numbers are converted to base-36 to save space in the URL. So what you can do is pull the url_id out of a link, convert it back to base-10, then look up the corresponding URL in the table rdir_url_tbl. You seem to understand the scripting language, so I think you can figure out how to do this.
Vicente
Posts: 1
Joined: Thu Jan 23, 2014 4:18 pm

Re: Action to update user field

Post by Vicente »

You need to indicate that changes have been made.

Code: Select all

#set($Customer.changeFlag = true)
The variable where you load the data can not be called like having parameters,

Code: Select all

## ERROR
#set($requestParameters=$Customer.getCustomerDataFromDb())

## OK
#set($parametros=$Customer.getCustomerDataFromDb())
The code

Code: Select all

#set($id = $requestParameters.CUSTOMERID)
#set($Int = 0)
#set($customerID = $Int.parseInt($id))

$ScriptHelper.println("---------------START----------------")
$ScriptHelper.println($requestParameters.lastname.toString())

$Customer.resetCustParameters()
$Customer.setCustomerID($customerID)
$Customer.setCompanyID(1)

$Customer.loadCustDBStructure()
##$Customer.loadAllBindings()
#set($parametros=$Customer.getCustomerDataFromDb())

## For each parameter we want to update a line like this:
#set($parametros.lastname=$requestParameters.lastname)

$ScriptHelper.println($parametros.lastname.toString())
$requestParameters.put("lastname", "MODIFIED LASTNAME")
$ScriptHelper.println($parametros.lastname.toString())

#if($Customer.importRequestParameters($parametros, null))
    $ScriptHelper.println("parametros SUCCESS")
#else
    $ScriptHelper.println("parametros FALSE")
#end

$ScriptHelper.println("$CustomerID | 1 | $parametros")
$ScriptHelper.println("changeFlag: $Customer.changeFlag")
#set($Customer.changeFlag = true)

#if($Customer.updateInDB())
    $ScriptHelper.println("Customer update SUCCESS")
    $ScriptHelper.println($Customer.lastname.toString())
#else
    $ScriptHelper.println("Customer update FALSE")
    $ScriptHelper.println($Customer.getCustomerDataFromDb().lastname)
#end

$ScriptHelper.println($Customer.getCustomerDataFromDb().lastname)

$ScriptHelper.println("-----END------")

#set($scriptResult="1")
Post Reply