[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
Poco Forums • View topic - Setting values in the address book?

Setting values in the address book?

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Setting values in the address book?

Postby jeremy_c » Fri Feb 05, 2010 1:47 pm

I would like to update one of the custom fields for a contact in the address book from my pocoscript. Is that possible? I am not seeing it in the reference but I am brand new to pocoscript, so I hope I am missing something.

Jeremy
jeremy_c
New Arrival
 
Posts: 4
Joined: Fri Feb 05, 2010 1:43 pm

Postby MarkB » Sun Feb 07, 2010 5:38 am

You have an existing script. You want a bit of code to add to it that will place new content in one of the 5 custom fields in an address book entry. Correct?

PocoScript has no high-level command for this purpose. We have to manipulate the raw address book entry. Which is easy enough. One theoretical problem with this is that the script will break if PocoSystems ever changes the position of the custom fields within the CSV structure.

A reminder: if you decide to experiment with this script, first back up you address books.

Problem 1: RemoveAddress. At least under Win7, the address does not disappear from the Contacts pane until Poco closes and re-opens. Perform RemoveAddress + AddRawAddress as this script does and you have two identical, updated entries in the Contacts pane. Do it 5 times, you get 6 identical, updated entries. The .ini file on disk is correct. The Contacts pane will correct itself when Poco re-opens.

Problem 2: Windows errors. At least under Win7, running this script throws up the familiar error pop-up that Win7 users have been reporting -- to wit, that Poco is attempting to write to an area of memory it isn't entitled to write to and was prevented doing so. On the upside, no harm is done, seemingly. On the downside, the user has to click many pop-ups, sometimes having to close Poco to get the darned pop-ups stopped.

Code: Select all
Set $address "testguy@zzzzzzz.com"
Set $addressbook "Main"
{  Custom field: 1, 2, 3, 4 or 5
Set #CustomFieldNumber 5
Set $newcontent "This is brand new content"



{  Begin ModifyAddressCustomField
{
{  Requires: $address, $addressbook, #CustomFieldNumber, $newcontent
{  For address books, not groups.
{  Problem, Win7: Entry isn't removed from Contacts pane until Poco closes and re-opens.
{  Problem, Win7: Lots of Windows "Can't write there" errors. No apparent harm done.
{  The silly names are to avoid conflicts with names in the container script

If #PocoVersion = 3000 Then EndIfVersion
MessageBox "This script has not been tested with this version of PocoMail."
Goto EndModifyAddressCustomField
:EndIfVersion

IsAddressPresent &flag $address $addressbook
If &flag Then EndIfPresent
MessageBox "Can't find the address"
Goto EndModifyAddressCustomField
:EndIfPresent

If #CustomFieldNumber < 1 Then BadCustomFieldNumber
If #CustomFieldNumber > 5 Then BadCustomFieldNumber
Goto EndIfNumber
:BadCustomFieldNumber
MessageBox "Number out of range"
Goto EndModifyAddressCustomField
:EndIfNumber

{  Read the addressbook entry into multi-line variable $entry
GetRawAddress $t $address $addressbook
ReadCSV $entry $t

{  Find the line we want
Set #t #CustomFieldNumber
Multiply #t 2
AddIntegers #t 20
Set #FieldLineNumber #t

{  Replace that line
DeleteLine $entry #FieldLineNumber 1
InsertLine $entry #FieldLineNumber $newcontent

{  Remove the original entry from the address book, and add the modified entry
RemoveAddress $addressbook $address
AddRawAddress $addressbook $entry

:EndModifyAddressCustomField

{  End ModifyAddressCustomField
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby jeremy_c » Mon Feb 08, 2010 3:39 am

MarkB wrote:PocoScript has no high-level command for this purpose. We have to manipulate the raw address book entry. Which is easy enough. One theoretical problem with this is that the script will break if PocoSystems ever changes the position of the custom fields within the CSV structure.


Thank you. I will work with this code today.

Jeremy
jeremy_c
New Arrival
 
Posts: 4
Joined: Fri Feb 05, 2010 1:43 pm


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 1 guest

cron