Parag Chapre

Create a customer/vendor using x++

In this article, We will see how to create a customer and vendor record using X/

Below is the code snippet for creating a customer record in X++.

public class CustomerCreateDemo
{
private void new()
{
}
public static CustomerCreateDemo construct()
{
    return new CustomerCreateDemo();
}
public void createCustomer()
{
    CustTable                    custTable;
    NumberSeq                    numberSeq;
    Name                         name ='Tesla';
    DirParty                        dirParty;
    DirPartyPostalAddressView       dirPartyPostalAddressView;
    DirPartyContactInfoView         dirPartyContactInfo;
    ;
    ttsBegin;
    custTable.initValue();
    try
    {
        //CustTable
        numberSeq              = NumberSeq::newGetNum(CustParameters::numRefCustAccount());
        custTable.AccountNum    = numberSeq.num();
        custTable.CustGroup     ='10';
        custTable.Currency      ='EUR';
        custTable.PaymTermId    ='USD10';
        custTable.PaymMode      ='CK';
        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      ='Tesla, USA ';
        dirPartyPostalAddressView.City              ='USA';
        dirPartyPostalAddressView.Street            ='Test';
        dirPartyPostalAddressView.StreetNumber      ='101';
        dirPartyPostalAddressView.CountryRegionId   ='USA';
        dirPartyPostalAddressView.State             ='NY';
        dirPartyPostalAddressView.IsPrimary             = NoYes::Yes;
        // Fill address
        dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);

        dirPartyContactInfo.LocationName    ='Email Address';
        dirPartyContactInfo.Locator         ='test@gmail.com';
        dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Email;
        dirPartyContactInfo.IsPrimary       = NoYes::Yes;
        // Fill Contacts
        dirParty.createOrUpdateContactInfo(dirPartyContactInfo);

        dirPartyContactInfo.LocationName    ='Mobile Number';
        dirPartyContactInfo.Locator         ='1234567889';
        dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Phone;
        dirPartyContactInfo.IsPrimary       = NoYes::Yes;
        // Fill Contacts
        dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
        // Marks the end of transaction.
        ttsCommit;
    }
    catch(Exception::Error)
    {
        ttsAbort;
        throw Exception::Error;
    }
}
}

Below is the code snippet for creating a vendor record in X++.

Public class VendorCreateDemo
{
    private void new()
    {
    }
    public static VendorCreateDemo construct()
    {
        return new VendorCreateDemo();
    }
    public void createVendor()
    {
        VendTable VendTable;
		NumberSeq numberSeq;
		Name name = 'Tesla';
	 
		DirParty dirParty;
		DirPartyPostalAddressView dirPartyPostalAddressView;
		DirPartyContactInfoView dirPartyContactInfo;
	 
		DirPartyTable dirPartyTable;
        ;
        
        ttsBegin;
        vendTable.initValue();
        try
        {
            //vendTable
            numberSeq               = NumberSeq::newGetNum(VendParameters::numRefVendAccount());
            vendTable.AccountNum    = numberSeq.num();
            vendTable.VendGroup     ='10';
            vendTable.Currency      ='EUR';
            vendTable.PaymTermId    ='USD10';
            vendTable.PaymMode      ='CK';
            vendTable.insert(DirPartyType::Organization, name);
            //DirParty
            /* Creates a new instance of the DirParty class from an address book entity
            that is represented by the vendTable parameter. */
            dirParty = DirParty::constructFromCommon(vendTable);
            dirPartyPostalAddressView.LocationName      ='Tesla, USA ';
            dirPartyPostalAddressView.City              ='USA';
            dirPartyPostalAddressView.Street            ='Test';
            dirPartyPostalAddressView.StreetNumber      ='101';
            dirPartyPostalAddressView.CountryRegionId   ='USA';
            dirPartyPostalAddressView.State             ='NY';
            dirPartyPostalAddressView.IsPrimary             = NoYes::Yes;
            // Fill address
            dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);

            dirPartyContactInfo.LocationName    ='Email Address';
            dirPartyContactInfo.Locator         ='test@gmail.com';
            dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Email;
            dirPartyContactInfo.IsPrimary       = NoYes::Yes;
            // Fill Contacts
            dirParty.createOrUpdateContactInfo(dirPartyContactInfo);

            dirPartyContactInfo.LocationName    ='Mobile Number';
            dirPartyContactInfo.Locator         ='1234567889';
            dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Phone;
            dirPartyContactInfo.IsPrimary       = NoYes::Yes;
            // Fill Contacts
            dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
            // Marks the end of transaction.
            ttsCommit;
        }
        catch(Exception::Error)
        {
            ttsAbort;
            throw Exception::Error;
        }
    }
}

If you like this article, feel free to share it with others who might find it helpful! If you have any questions, feel free to reach out to me.

Leave a Reply

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