Calling the Contacts Service in AX 2012

By Becky Newell | January 28, 2014

In AX 2012 there is a service called DirContactPersonsService which allows you to import contacts.  The contacts imported via this service are displayed under Sales and marketing > Common > Contacts > All contacts.  The DirContactPersonsService is somewhat tricky to call because a contact can be created for either a customer, vendor or a prospect and you have to specify in your service call who you are creating the contact for.  Having said that, here is an example of how to call the service creating a contact for a customer:

 

ContactPersonsServiceClient client = new ContactPersonsServiceClient();

CallContext context = new CallContext();

context.Company = “ceu”;

 

AxdContactPersons contactPersons = new AxdContactPersons();

 

AxdEntity_ContactPerson[] contacts = new AxdEntity_ContactPerson;

AxdEntity_ContactPerson contact = new AxdEntity_ContactPerson();

contact.ContactForPartyCustAccount = “10076”; //Set this to the account number of the customer account

//If this is a contact for a vendor use the contact.ContactForPartyVendAccount

 

//Create the party record

AxdEntity_Person_DirPerson person = new AxdEntity_Person_DirPerson();

person.NameAlias = “ContactFTest”;

person.NameSequence = “FirstMiddleLast”;

 

//Set the name fields

AxdEntity_PersonName personName = new AxdEntity_PersonName();

personName.FirstName = “ContactFTest”;

personName.MiddleName = “MiddleTest”;

personName.LastName = “LastTest”;

 

 

//Add the names to the party record and set the name sequence

person.PersonName = new AxdEntity_PersonName { personName };

 

AxdEntity_PostalAddressView address = new AxdEntity_PostalAddressView();

address.LocationName = “Location Name”;

address.Street = “111 NE 5th St”;

address.City = “Beverly Hills”;

address.State = “CA”;

address.CountryRegionId = “USA”;

address.ZipCode = “90210”;

address.Roles = “Business”;

address.IsPrimary = AxdExtType_LogisticsIsPrimaryAddress.Yes;

address.IsPrimarySpecified = true;

 

AxdExtType_EffectiveDateTime myDateTime = new AxdExtType_EffectiveDateTime();

myDateTime.localDateTime = Convert.ToDateTime(“1/15/2014”);

myDateTime.localDateTimeSpecified = true;

myDateTime.timezone = AxdEnum_Timezone.GMTMINUS0600CENTRALTIME;

myDateTime.timezoneSpecified = true;

address.ValidFrom = myDateTime;

AxdExtType_ExpirationDateTime expireDateTime = new AxdExtType_ExpirationDateTime();

expireDateTime.localDateTime = Convert.ToDateTime(“12/20/2020”);

expireDateTime.localDateTimeSpecified = true;

expireDateTime.timezone = AxdEnum_Timezone.GMTMINUS0600CENTRALTIME;

expireDateTime.timezoneSpecified = true;

address.ValidTo = expireDateTime;

 

//Create an email address

AxdEntity_ContactInfoView email = new AxdEntity_ContactInfoView();

email.LocationName = “Contact Email”;

email.Type = AxdEnum_LogisticsElectronicAddressMethodType.Email;

email.TypeSpecified = true;

email.Locator = “whatever@hotmail.com“;

email.Roles = “Home”;

 

//Create a phone number

AxdEntity_ContactInfoView cellPhone = new AxdEntity_ContactInfoView();

cellPhone.LocationName = “Cell phone”;

cellPhone.Type = AxdEnum_LogisticsElectronicAddressMethodType.Phone;

cellPhone.TypeSpecified = true;

cellPhone.Locator = “555-123-1234”;

cellPhone.Roles = “Home”;

 

contact.Person = new AxdEntity_Person_DirPerson { person };

contact.Person.PostalAddressView = new AxdEntity_PostalAddressView { address };

contact.Person.ContactInfoView = new AxdEntity_ContactInfoView { email, cellPhone };

contacts = contact;

contactPersons.ContactPerson = contacts;

 

try

{

client.create(context, contactPersons);

Console.ReadLine();

}

catch (Exception e)

{

string message = e.Message;

}

Related Posts

Recommended Reading:

Manage U.S. Use Tax on Purchase Orders in Dynamics 365 Finance and Operations

  Managing sales tax requirements on your business purchase can be complicated, but Dynamics 365 Finance and Operations can help […]

Read the Article
5.19.22 Dynamics CRM

How to Write a Great Support Ticket in the Stoneridge Support Portal

Submitting a support ticket through the Stoneridge Support Portal is a quick and effective way to get assistance for any […]

Read the Article

Managing Your Business Through Uncertain Times Using Dynamics 365 Finance and Operations

  Dynamics 365 Finance and Operations (F&O) can help you make informed decisions on how to move your business forward. […]

Read the Article
5.13.22 Power Platform

Using Power BI Object Level Security

  The following article will demonstrate how to use Power BI Object Level Security to disable column data based on […]

Read the Article
5.12.22 Dynamics CRM

How to Use the Stoneridge Support Portal

Stoneridge Software’s support portal is an intuitive and useful function that makes it easy for you to access resources to […]

Read the Article
5.6.22 Dynamics GP

Dynamics GP Transaction Removal: Purchase Orders

  Are you having performance issues with Purchase Orders?  Do you find that there are old Purchase Orders on your […]

Read the Article
5.5.22 Dynamics GP

The Real Story about the Long-Term Future of Dynamics GP Support

I’ve seen a number of people put forward comment that Dynamics GP is going away and you have to get […]

Read the Article

New Features in Dynamics 365 Business Central 2022 Wave 1 Release – Financial Enhancements

The Dynamics 365 Businses Central 2022 Wave 1 Release has a lot of new and exciting features to help your […]

Read the Article
4.29.22 Dynamics GP

Dynamics GP Transaction Removals: Bank Reconciliation

  This is part 2 of a 3 part series on Dynamics GP Transaction Removals. These quick tips will hopefully […]

Read the Article

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!

X