Hi all.
I've been struggling with the labyrinthine database structure of SugarCRM all afternoon and I'm going SQL blind. I wondered if anyone else had tried to do this.
So, as the title suggests, a bunch of contacts were added to a Target List. Since then the data has been tidied up and I'd like to remove all the contacts on the target list which don't have email addresses. There are 4000 people on the list, so this is clearly not a manual process, especially as the Target list module will only show 20 names at a time.
So, while it was easy to add multiple names to a target list using Mass Update and Power Prospecting, it is hard to maintain those lists.
First stop was of course through the Web Interface. I can use Advanced search to get all the people on a target list. However.
a) I can't find all those who have an empty email address and
b) I can't sort by email address in the results and
c) Even if I could get all the empty email addresses selected, there is no way of doing a mass update to remove them from a Target List.
So, database it is then ....
First I got the id of the Target list, which by the time you're in the database is called a prospect list.
Which gave me the prospect list id. A quick check then ...Code:SELECT * FROM `prospect_lists
Yup, that's the list I want. But there's no easy path from here, so what I planned to do is get all the ids of contacts with an empty email address ...Code:SELECT * FROM prospect_lists_prospects WHERE prospect_list_id ="4d850c13-7da3-5aac-b39a-4ae7fb91d055" AND related_type = "Contacts" AND deleted=0
And then use that to delete the 'No Email Address' Contacts from the table which associates contacts with prospect lists eg.Code:SELECT contacts.id FROM contacts LEFT JOIN email_addr_bean_rel on contacts.id=email_addr_bean_rel.bean_id LEFT JOIN email_addresses on email_addr_bean_rel.email_address_id=email_addresses.id WHERE email_addresses.email_address IS NULL
Well that looked good, except it still leaves a bunch of contacts who used to have email addresses associated with them, and which was deleted. However, the pointer in email_addr_bean_rel is still there so the email address is picked up.Code:DELETE FROM prospect_lists_prospects WHERE prospect_lists_prospects.related_id IN ("10770f41-c3fa-9e47-d386-4a4993d8a378", ...etc...."10a6006b-fbb7-ad2a-a4ff-4a498dabeb43")
I've tried limiting the query with email_addresses.deleted =1 but that doesn't work -- email addresses are not marked with deleted=1 when they're deleted (! apparently ...) and
email_addr_bean_rel.deleted = 1 doesn't help either.
Where do I go from here ...


LinkBack URL
About LinkBacks



Reply With Quote
.... 

Bookmarks