web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / DAX Beginners / How to: Create customer thr...

How to: Create customer through X++

Christian Silva Profile Picture Christian Silva 707

Today I decided to post something simple,useful and where I could test source code on WordPress.

A post teaching how to create a Customer through X++ couldn’t be more perfect.
There is many many tables related to CustAccount and create it through code is a nightmare,
thank god Microsoft created methods and classes to make our life easier like the DirPartyTable
method ConstrucFromCommon that creates contact info for our customer.

I made it using a Job but you shouldn’t have problems to use it on a class or form method.

// Create a new Job
static void JobCreateCustomer (Args _args)
{
    CustTable                    custTable;
    NumberSeq                    numberSeq;
    Name                         name ='SouthSide Street LTDA';

    DirParty                        dirParty;
    DirPartyPostalAddressView       dirPartyPostalAddressView;
    DirPartyContactInfoView         dirPartyContactInfo;
    ;

    /* Marks the beginning of a transaction.
       Necessary to utilize the method numRefCustAccount() */
    ttsBegin;
    custTable.initValue();

   try
    {
       //CustTable
        numberSeq               = NumberSeq::newGetNum(CustParameters::numRefCustAccount());
        custTable.AccountNum    = numberSeq.num();
        custTable.CustGroup     ='020';
        custTable.Currency      ='BRL';
        custTable.PaymTermId    ='10DD';
        custTable.PaymMode      ='CHEQUE-01';

        custTable.insert(DirPartyType::Organization, name);

        //DirParty

        /* Creates a new instance of the DirParty class from an address book entity
           that is represented by the custTable parameter. */
        dirParty = DirParty::constructFromCommon(custTable);

        dirPartyPostalAddressView.LocationName      ='HeadQuarters ';
        dirPartyPostalAddressView.City              ='São Paulo';
        dirPartyPostalAddressView.Street            ='4th Avenue';
        dirPartyPostalAddressView.StreetNumber      ='18';
        dirPartyPostalAddressView.CountryRegionId   ='BRA';
        dirPartyPostalAddressView.State             ='SP';

        // Fill address
        dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);

        dirPartyContactInfo.LocationName    ='SouthStreet Contact Phone';
        dirPartyContactInfo.Locator         ='551291165341';
        dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Phone;
        dirPartyContactInfo.IsPrimary       = NoYes::Yes;

        // Fill Contacts
        dirParty.createOrUpdateContactInfo(dirPartyContactInfo);

        // Marks the end of transaction.
        ttsCommit;
    }
    catch(Exception::Error)
    {
       ttsAbort;
       throwException::Error;
    }
}


This was originally posted here.

Comments

*This post is locked for comments