Removal of duplicate emails for a contact
Summary
Script to remove emails with .00XXContent
Hi All,
I've added the below script in one of my report to delete duplicate emails
Scenario: email_alt1 is valid and email_alt2 is duplicate and has .00
|
I am unsure why works sometimes but not in this scenario. Can anyone please look at my code and advise if I have overlooked something?
Thank you,
Kate
Version
19ACode Snippet
require_once(get_cfg_var('doc_root') . '/include/ConnectPHP/Connect_init.phph' ); initConnectAPI(); putenv('TEMPORARY_RNW_CONF_DIRECTORY'); use RightNow\Connect\v1_3 as RNCPHP; $ar= RNCPHP\AnalyticsReport::fetch('#C1.DUP.EML.DEL.PREV'); $arr = $ar->run(); echo "Number of records to be processed is: ".$arr->count() . "<br>"; for ($i = $arr->count(); $i--;) { $note = null; $row = $arr->next(); $email_alt2 = null; $primary_email = null; $email_alt1 = null; echo "Record count processing is: ".$i."<br>"; //Alt1 email is valid if((!preg_match('^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}.[\d]{4}$',$row['email_alt1']))){ //Alt2 email is invalid if((preg_match('^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}.[\d]{4}$',$row['email_alt2']))){ $subalt2=substr($row['email_alt2'],0,-5); if($row['email_alt1']==$subalt2){ echo "<br>Alt1 and Alt2 emails have the same value, contact ID is: ".$row['Contact ID']."<br>"; $contact = RNCPHP\Contact::first("ID = ".$row['Contact ID']); $note = "Alt1 and Alt2 have same Emails.\n"; $note .= "Email Alt 1 is valid: : ".$contact->Emails[1]->Address."\n"; $note .= "Email Alt 2 address value before removing was: : ".$contact->Emails[2]->Address."\n"; $note_store = saveNote($contact,$note); //delete email alt2 $contact->Emails->offsetUnset(2); $contact->save(); RNCPHP\ConnectAPI::commit(); } } //Primary email is
Tagged:
0