How to get contact keywords using the Tridion Outbound Email API?

I use the Tridion.OutboundEmail.ContentManagement API to get and manage contact details.

Getting contacts works fine since it returns an ExtendedDetails dictionary, but the TcmUriCollection keywords are always empty.

[Test] public void GetContacts_via_address_book() { var uri = new TcmUri(101, 2, TcmItemTypes.StaticAddressBook); var addressBook = new StaticAddressBook(uri); var contacts = addressBook.GetContacts(); foreach (var contact in contacts) { var firstName = contact.ExtendedDetails["NAME"].StringValue; Assert.That(contact.EmailAddress, Is.Not.Empty); // PASS Assert.That(firstName, Is.Not.Empty); // PASS Assert.That(contact.Keywords.Count, Is.GreaterThan(0)); // FAIL } } 

I also tried the following method:

 [Test] public void GetContacts_via_filter() { var uri = new TcmUri(101, 2, TcmItemTypes.StaticAddressBook); var addressBook = new StaticAddressBook(uri); var filter = new ContactFilter(UserContext.Current); var contacts = Contact.GetContacts(filter, addressBook); foreach (var contact in contacts) { var firstName = contact.ExtendedDetails["NAME"].StringValue; Assert.That(contact.EmailAddress, Is.Not.Empty); // PASS Assert.That(firstName, Is.Not.Empty); // PASS Assert.That(contact.Keywords.Count, Is.GreaterThan(0)); // FAIL } } 

I can even add a keyword to the contact keywords collection and save it, and it displays correctly in Tridion, but when I get the same contact again, the collection is empty again.

Does anyone have experience with this API and / or know what the problem is?

+4
source share
1 answer

This is because keywords do not load when you get your contact list. For performance reasons, only a subset of the data is available.

To solve this problem, you will need to restart each Contact. Since Contacts are transferred from the database, you cannot do this inside your loop. Thus, you need to first create a list of contacts, and then iterate over them and download them completely.

For more information and examples, please see my related blog post: http://pkjaer.wordpress.com/2011/12/01/looping-through-contacts/

+6
source

Source: https://habr.com/ru/post/1401195/


All Articles