Calling the Contacts Service in AX 2012

by | Updated August 15, 2016 | Development, Dynamics AX

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[1];

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[1] { 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[1] { person };

contact.Person[0].PostalAddressView = new AxdEntity_PostalAddressView[1] { address };

contact.Person[0].ContactInfoView = new AxdEntity_ContactInfoView[2] { email, cellPhone };

contacts[0] = contact;

contactPersons.ContactPerson = contacts;

 

try

{

client.create(context, contactPersons);

Console.ReadLine();

}

catch (Exception e)

{

string message = e.Message;

}

Related Posts

  • The Safari browser is now supported natively on Dynamics AX 2012 R2 as well as being supported on Dynamics AX RTM with a hotfix.  Taken from the updated System Requirements…

  • I put together some certification information on the requirements for Microsoft Dynamics AX 2012 and a proposed training roadmap to get to each of the core certifications.  Rather than have this…

  • With the announcement of the release of Microsoft Dynamics AX 2012 R2, Microsoft released an updated system requirements document for AX 2012: http://www.microsoft.com/en-us/download/details.aspx?id=11094.  Windows 2012 Server is now supported, but…

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Upcoming Events

september

02sep10:00 am10:30 amThe Modern Manufacturer - Cycle Count Management

02sep12:00 pm12:30 pmBest Practices for Work Order Planning and Routing for Field Service Companies

09sep10:00 am11:00 amWhat is Levridge? An Overview of the Ultimate Ag Solution

09sep12:00 pm12:30 pmOverview of Microsoft Promotion for NAV and GP Clients

10sep11:00 am12:00 pmConfab with Stoneridge - Livestream - Field Service Comparisons

16sep10:00 am10:30 amThe Modern Manufacturer - Product Lifecycle Management

16sep12:00 pm12:30 pmHow to Upgrade to Dynamics 365 Finance and Operations: Examining Custom Code and ISV Implications

16sep2:00 pm2:30 pmScheduling and Dispatching for the Modern Field Service Company

23sep12:00 pm1:00 pmDynamics 365 Business Central Wave 2 Release Preview - An Overview of the Most Exciting New Features Coming in October

24sep11:00 am12:00 pmConfab with Stoneridge - Livestream - The Modern Workplace: Teams, Sharepoint, Outlook, Office, and AI Integration

30sep10:00 am10:30 amThe Modern Manufacturer - Return Management

30sep12:00 pm12:30 pmEmpowering Your Field Service Technicians with a Mobile Solution

october

07oct12:00 pm1:00 pmThe Three Paths to Business Central from Dynamics GP

08oct11:00 am12:00 pmConfab with Stoneridge - Livestream - The Vision and Strategy of Microsoft Business Systems

14oct10:00 am10:30 amThe Modern Manufacturer - Complex Cost Modeling

14oct12:00 pm12:30 pmGenerating Custom Inspection or Process Forms

19octAll Day22Stoneridge Connect Fall 2020

22oct11:00 am12:00 pmConfab with Stoneridge - Livestream - Stoneridge Connect Recap

28oct10:00 am10:30 amThe Modern Manufacturer - Engineering Change Orders

About Stoneridge
Stoneridge Software is a unique Microsoft Gold Partner, with emphasis on partner. With specialties in Microsoft Dynamics 365, Microsoft Dynamics AX, Microsoft Dynamics NAV, Microsoft Dynamics GP and Microsoft Dynamics CRM, we focus on attracting the most knowledgeable experts in the field to our team, and prioritize delivering stellar solutions with maximum impact for your business. At Stoneridge, we are deeply committed to your results. Each engagement is met with a dedicated team, ready to provide thorough, tailored, and expert service. Based in Minnesota, we intentionally “step into your shoes,” wherever you are. We focus on what you care about, and develop trusting, long-term relationships with our clients.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!

X