Community
Showing results for 
Search instead for 
Do you mean 
Reply

How to sort the currentContactList based on the alphabetical order of the Mail-addresses

Accepted Solution Solved
Copper Contributor
Posts: 32
Country: Germany
Accepted Solution

How to sort the currentContactList based on the alphabetical order of the Mail-addresses

 

Hi,

 

i'm not sure how to use the sort-method to sort the currentContactList based on the alphabetical order of the Mail-addresses.

 

Any ideas?


Accepted Solutions
Solution
Accepted by topic author benoit22
‎09-25-2015 03:20 AM
Copper Super Contributor
Posts: 86
Country: United_Kingdom

Re: How to sort the currentContactList based on the alphabetical order of the Mail-addresses

[ Edited ]

benoit22 wrote:

 

After the SetCurrentContactList-method is executed  Act jumps back to the Listview with all Contacts and sort the Mail-addresses in alphabetical order.

So the sort-algorithm works but my selected contacts are lost.

Might have something to do with the arguments of  the SetCurrentContactList-method?

 


It's because in my example I get ALL Contacts and sort by e-mail, then pass this list to the Contact List View.

You'll need to modify the code a little to sort your current lookup before showing the results.

 

Edit: I had a few minutes spare to write an example.

 

Replace this line:

 

ContactList cl = actApp.ActFramework.Contacts.GetContacts(sc);

 

 With this:

 

ContactList cl = actApp.ApplicationState.CurrentContactList;
cl.Sort(sc);

 

Now it will sort the current lookup.

 

Kind regards,

 

Sam.

____________________________________________________________

Unfortunately I no longer work for Swiftpage International. Please do not send any queries to this account.

View solution in original post


All Replies
Copper Super Contributor
Posts: 86
Country: United_Kingdom

Re: How to sort the currentContactList based on the alphabetical order of the Mail-addresses


benoit22 wrote:

 

Hi,

 

i'm not sure how to use the sort-method to sort the currentContactList based on the alphabetical order of the Mail-addresses.

 

Any ideas?


Hi Benoit22,

 

Here is some code to sort the Contact List by E-mail. It's written in C#.

 

ContactFieldDescriptor cfd = actApp.ActFramework.Contacts.GetContactFieldDescriptor("E-mail", FieldNameType.Alias);
SortCriteria[] sc = new SortCriteria[] { new SortCriteria(cfd, ListSortDirection.Ascending) };
ContactList cl = actApp.ActFramework.Contacts.GetContacts(sc);       actApp.ApplicationState.SetCurrentContactList(cl, null);

 I hope this helps.

 

Kind regards,

 

Sam.

____________________________________________________________

Unfortunately I no longer work for Swiftpage International. Please do not send any queries to this account.
Copper Contributor
Posts: 32
Country: Germany

Re: How to sort the currentContactList based on the alphabetical order of the Mail-addresses

[ Edited ]

 

Thanks sam_raikes,

 

that was very helpful.

Still there is one thing:

(first the code)

 

Act.Framework.Contacts.ContactFieldDescriptor cfd = ActFr.Contacts.GetContactFieldDescriptor("E-MAIL", FieldNameType.Alias);

Act.Shared.Collections.SortCriteria[] sc = new Act.Shared.Collections.SortCriteria[] { new Act.Shared.Collections.SortCriteria(cfd, System.ComponentModel.ListSortDirection.Ascending) };

Act.Framework.Contacts.ContactList cl = actApp.ActFramework.Contacts.GetContacts(sc);

actApp.ApplicationState.SetCurrentContactList(cl, null);

 

After the SetCurrentContactList-method is executed  Act jumps back to the Listview with all Contacts and sort the Mail-addresses in alphabetical order.

So the sort-algorithm works but my selected contacts are lost.

 

 

Solution
Accepted by topic author benoit22
‎09-25-2015 03:20 AM
Copper Super Contributor
Posts: 86
Country: United_Kingdom

Re: How to sort the currentContactList based on the alphabetical order of the Mail-addresses

[ Edited ]

benoit22 wrote:

 

After the SetCurrentContactList-method is executed  Act jumps back to the Listview with all Contacts and sort the Mail-addresses in alphabetical order.

So the sort-algorithm works but my selected contacts are lost.

Might have something to do with the arguments of  the SetCurrentContactList-method?

 


It's because in my example I get ALL Contacts and sort by e-mail, then pass this list to the Contact List View.

You'll need to modify the code a little to sort your current lookup before showing the results.

 

Edit: I had a few minutes spare to write an example.

 

Replace this line:

 

ContactList cl = actApp.ActFramework.Contacts.GetContacts(sc);

 

 With this:

 

ContactList cl = actApp.ApplicationState.CurrentContactList;
cl.Sort(sc);

 

Now it will sort the current lookup.

 

Kind regards,

 

Sam.

____________________________________________________________

Unfortunately I no longer work for Swiftpage International. Please do not send any queries to this account.
Copper Contributor
Posts: 32
Country: Germany

Re: How to sort the currentContactList based on the alphabetical order of the Mail-addresses

[ Edited ]

Sorry,

 

now it works:

 

int contact_number = ACT_app.ActAppl.ApplicationState.CurrentContactList.Count;

              Guid[] contact_IDs = new Guid[contact_number];
           
              int counter = 0;
             
              foreach (Act.Framework.Contacts.Contact contact in ACT_app.ActAppl.ApplicationState.CurrentContactList)
              {
                contact_IDs[counter] = contact.ID;
                counter++;
              }

             Act.Framework.Contacts.ContactFieldDescriptor cfd = ActFr.Contacts.GetContactFieldDescriptor("E-MAIL", FieldNameType.Alias);

               Act.Shared.Collections.SortCriteria[] sc = new Act.Shared.Collections.SortCriteria[] { new Act.Shared.Collections.SortCriteria(cfd, System.ComponentModel.ListSortDirection.Ascending) };

               Act.Framework.Contacts.ContactList cl = actApp.ActFramework.Contacts.GetContactsByID(sc, contact_IDs);

               actApp.ApplicationState.SetCurrentContactList(cl, null);

 

Copper Contributor
Posts: 32
Country: Germany

Re: How to sort the currentContactList based on the alphabetical order of the Mail-addresses

Or so :-)