How to: Create customer through X++

Posted on Updated on

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() */

        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);


        /* 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

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

        // Fill Contacts

        // Marks the end of transaction.

2 thoughts on “How to: Create customer through X++

    pkc said:
    September 11, 2014 at 2:44 am

    DirParty dirParty;
    DirPartyPostalAddressView dirPartyPostalAddressView;
    DirPartyContactInfoView dirPartyContactInfo;

    what does this mean cn you expalin it a little bit more……… i am new to it

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s