Tuesday, August 19, 2025

Create contact person using x++ d365fo


    NumberSeq               numberSeq;

    ContactPersonSyncEntity contactPersonEntity;

    container               roleContainer;

    // Generate new Contact Person ID

    ttsbegin;

    numberSeq                        = NumberSeq::newGetNum(ContactPerson::numRefContactPersonId());

    contactPerson.ContactPersonId    = numberSeq.num();

    numberSeq.used();

    ttscommit;

    // Create Contact Person record

    ttsbegin;

    contactPerson.CustAccount        = 'Test001';

    contactPersonEntity              = ContactPersonSyncEntity::construct(contactPerson);

    contactPersonEntity.parmContactPersonId(contactPerson.ContactPersonId);

    contactPersonEntity.parmFirstName("FirstName");

    contactPersonEntity.parmLastName('Last name');

    contactPersonEntity.parmLanguageId('US-EN');

    contactPersonEntity.write();

    ttscommit;

//  create postal address for contact person

DirPartyPostalAddressView       postalAddressView;

LogisticsPostalAddress          logisticsPostalAddress;

LogisticsLocation               logisticsLocation;

LogisticsAddressStreet          street;

DirParty                        dirParty = DirParty::constructFromCommon(contactPerson);

DirPartyLocation                dirPartyLocation;

boolean                         ret = true;

DirPartyPostalAddressView       partyPostalAddressView;

ttsbegin;

logisticsLocation.clear();

logisticsLocation.Description = 'test desc';

logisticsLocation.IsPostalAddress = true;

logisticsLocation.LocationId = '001234';

logisticsLocation.insert();

logisticsPostalAddress =  LogisticsPostalAddress::findByLocation(logisticsLocation.RecId, true);


if(!logisticsPostalAddress.RecId)

{

    logisticsPostalAddress.clear();

}

        

logisticsPostalAddress.CountryRegionId  = 'US';

logisticsPostalAddress.State            = 'Test state';

logisticsPostalAddress.County           = 'US';

logisticsPostalAddress.City             = 'test city';

logisticsPostalAddress.ZipCode          = '989238';

logisticsPostalAddress.Street           = 'test street';

logisticsPostalAddress.Location         = logisticsLocation.RecId;


postalAddressView.initFromPostalAddress(logisticsPostalAddress);

postalAddressView.LocationName  = 'Business';

postalAddressView.Party         = contactPerson.Party;

postalAddressView.IsPrimary     = true;

postalAddressView.ProArIsCreatedByIntegration = true;

partyPostalAddressView = DirParty.createOrUpdatePostalAddress(postalAddressView,LogisticsLocationRole::findByName('Business').RecId);

ttscommit;



Call API using x++ D365FO

 System.Net.HttpWebRequest    request; System.Net.HttpWebResponse   response; System.IO.Stream             dataStream; System.IO.StreamReade...