Sort is not working for email field in contact module list view

Hello,

Can anyone help how we can make sort working for the email field?

Thanks
Jyoti

Hello!!!

I think I found the solution for this little issue. Try it and let me know.

Edit:
/modules/Contacts/metadata/listviewdefs.php

and change these values.

Line 95 & Line 125
ā€˜sortableā€™ => false,
into
ā€˜sortableā€™ => true,

whoo hoo!

time passedā€¦ testedā€¦ hmm. Hold off on trying thisā€¦ maybe it will not work. It was workingā€¦ hmm

Yeah no go hereā€¦ Just seen this awful message in the suitecrm.log

Tue Jul 14 19:12:03 2020 [21321][1][FATAL] Mysqli_query failed.
Tue Jul 14 19:12:03 2020 [21321][1][FATAL]  Query Failed:  SELECT  contacts.id , contacts.assigned_user_id , LTRIM(RTRIM(CONCAT(IFNULL(contacts.first_name,''),' ',IFNULL(contacts.last_name,'')))) as name, contacts.first_name , contacts.last_name , contacts.salutation  , accounts.name account_name, jtl0.account_id account_id, contacts.title , contacts.phone_work  , jt1.user_name assigned_user_name , jt1.created_by assigned_user_name_owner  , 'Users' assigned_user_name_mod, contacts.date_entered , contacts.created_by  FROM contacts  LEFT JOIN contacts_cstm ON contacts.id = contacts_cstm.id_c   LEFT JOIN  accounts_contacts jtl0 ON contacts.id=jtl0.contact_id AND jtl0.deleted=0

 LEFT JOIN  accounts accounts ON accounts.id=jtl0.account_id AND accounts.deleted=0
 AND accounts.deleted=0  LEFT JOIN  users jt1 ON contacts.assigned_user_id=jt1.id AND jt1.deleted=0

 AND jt1.deleted=0 where contacts.deleted=0 ORDER BY email1 LIMIT 0,21: MySQL error 1054: Unknown column 'email1' in 'order clause'

yup. nightmare. If you do the above. and then actually Click on the ā€œEmailā€ Header to do a ā€œsortā€

LOOK OUT!!

by doing thatā€¦ you then tell the system that you want to sortā€¦ it will sort onceā€¦ and then BANG. things go really bad. There will ne NO way to recover out of this to get your contacts back visible because the system wants to sort by the email1 fieldā€¦ This sorting causes a ā€œORDER BY email1ā€ query string that causes the above error log to bark out the FATAL messages and never actually call into the contact database to populate the list. hmm

I think a join isnā€™t happening that shouldā€¦ as the sql statement is saying

ā€œMySQL error 1054: Unknown columnā€

so thus the email1 is not getting located in the initiated SELECTā€¦ hmmā€¦

I will see if I can dig more into thisā€¦ not sure if I can climb this mountain.

**** DING DING ****

Lets say you ended up doing the aboveā€¦ without reading my LOOK OUT. then wellā€¦ here is the answer. omg. it wasnā€™t easy finding this but I did. well it was a little easyā€¦ little not.

you will need to go into the /data/sugar/SugarBean.php and scroll down to line 4094 and add a
`

return ā€œā€;

Then run your suiteCRM and then load up your previously empty contacts list and click on ANY of the other columns except ā€œemailā€ ā€¦ and then go back to the

/data/sugar/SugarBean.php

and delete your previoulsly placed

return ā€œā€;

then BINGO. All your contacts will no appear again. Whewwwā€¦ nightmare. I was worried for a bit.

wow. like what was thinkingā€¦ " yeah fix the email sorting issue"

ahahah i will let time pass and see what happensā€¦

after a few minutes I will see if I can continue tackling thisā€¦ I think I have a idea on how it might be possible.
`

Emails are stored in a separate table (itā€™s a one-to-many relationship, there can be many emails per record). The email1 is a hack to facilitate grabbing the primary email.

Remember that changing things in core code is not upgrade-safe. You should always keep your customizations strictly to the custom folder.

Hello @burndata,

Thanks for your reply :).

Yes before posting here i tried this solution but it didnt work. even if you change false to true it will not work.

If i change ā€˜sortableā€™ => false, to true and then click on sort button, in result nothing has come, so to get all record back I filtered and click on clear button and then click on search button, by doing that i got all records back.

So still finding a solution.

Hello @pgr,

Thanks for reply :).

Can you guide me how we can make sort option which works for email field?

Sorry, no. It is not simple and I donā€™t know how to do it.

I wish I could find this ā€œClearā€ button. hahah I was forced in a email1 sorting nightmare.

with a little work I did end up getting the emails to show up and the query not to error out anymoreā€¦
but like everything that is goodā€¦ It is hard. Very very tricky stuff here.

like @pgr has notedā€¦ it is a one-to-many relationship. just take a look in the /data/Link.php to really get a mind-altering wtf.

I believe it is WAY above my pay grade at this time to be doing this. I have told myself, ā€œDo I really really need to sort the email addresses that I will have in there?ā€

"I say no. " haha . on to other tasks that maybe I can solve.

1 Like