Translate

Saturday, June 16, 2012

Creating Vendors thru X++ in AX 2012

Creating Vendors thru X++ in AX 2012


1.
//Create party for the vendor
public void createParty(VendorRequestCreate          _vendorRequestCreate)
{
    ;
    if(_vendorRequestCreate.DirPartyType        == DirPartyBaseType::Person)
    {
        dirPerson.Name                          = _vendorRequestCreate.VendorName;
        dirPerson.NameAlias                     = _vendorRequestCreate.FirstName;
        dirPerson.NameSequence                  = dirNameSequence::find('First Last').RecId;
        dirPerson.insert();

        dirPersonName.FirstName                 = _vendorRequestCreate.FirstName;
        dirPersonName.MiddleName                = _vendorRequestCreate.MiddleName;
        dirPersonName.LastName                  = _vendorRequestCreate.LastName;
        dirPersonName.ValidFrom                 = DateTimeUtil::newDateTime(systemDateGet(),str2time ('00:00:00'),DateTimeUtil::getUserPreferredTimeZone());
        dirPersonName.ValidTo                   = DateTimeUtil::maxValue();
        dirPersonName.Person                    = dirPerson.RecId;
        dirPersonName.insert();

        dirParty                                = new DirParty(dirPerson);
    }
    else
    {
        dirOrganisation.Name                    = _vendorRequestCreate.VendorName;
        dirOrganisation.NameAlias               = _vendorRequestCreate.FirstName;
        dirOrganisation.LanguageId              = 'EN-US';
        dirOrganisation.KnownAs                 = _vendorRequestCreate.VendorName;
        dirOrganisation.PhoneticName            = _vendorRequestCreate.VendorName;
        dirOrganisation.insert();

        dirParty                                = new DirParty(dirOrganisation);
    }

}


2.

//Create vendor and associate with vendor
public void convertToVendor(VendorRequestCreate          _vendorRequestCreate)
{
    VendorRequestCreate                  vendorRequestCreate = VendorRequestCreate::find(_vendorRequestCreate.VendorNo,true);
    ;

    if(_vendorRequestCreate.DirPartyType    == DirPartyBaseType::Person)
        vendTable.Party         = dirPerson.RecId;
    else
        vendTable.Party         = dirOrganisation.RecId;

    ttsBegin;
    vendTable.AccountNum    = NumberSeq::newGetNum(VendParameters::numRefVendAccount()).num();
    ttsCommit;
    if(vendTable.AccountNum == '')
        vendTable.AccountNum= int2str(_vendorRequestCreate.VendorNo);

    vendTable.Currency      = _vendorRequestCreate.CurrencyCode;
    vendTable.VendGroup     = _vendorRequestCreate.VendGroupId;
    vendTable.PaymTermId    = _vendorRequestCreate.PaymTermId;
    vendTable.DefaultDimension = _vendorRequestCreate.DefaultDimension;
    vendTable.OneTimeVendor = _vendorRequestCreate.OneTimeSupplier;
    vendTable.PaymMode      = _vendorRequestCreate.PaymMode;
    vendTable.BankAccount   = _vendorRequestCreate.BankAccount;
    vendTable.WI_Remarks    = _vendorRequestCreate.Remarks;
    vendTable.WI_DepartmentEmail = _vendorRequestCreate.DepartmentEmail;
    vendTable.insert();

    this.createPostalAddress(_vendorRequestCreate);
    this.createCommAddress(_vendorRequestCreate);
    this.createBankDetails(_vendorRequestCreate,vendTable.AccountNum);
    this.createContact(_vendorRequestCreate,vendTable.Party);

    if(vendTable.RecId)
    {
        vendorRequestCreate.VendAccount = vendTable.AccountNum;
        vendorRequestCreate.update();
        info(strFmt('Vendor %1 has been successfully created',vendTable.AccountNum));
    }

}


3.

//Create postal address
public void createPostalAddress(VendorRequestCreate          _vendorRequestCreate)
{
    VendorRequestAddress             vendorRequestAddress;
    DirPartyPostalAddressView           dirPartyPostalAddressView;
    ;

    select Addressing, LogisticsAddressCity, LogisticsAddressCountryRegionId, LogisticsAddressStateId,
            LogisticsAddressZipCodeId from vendorRequestAddress
        where vendorRequestAddress.WI_VendorRequestCreate       == _vendorRequestCreate.RecId;

    // Create postal address
    if(dirPerson.RecId || dirOrganisation.RecId)
    {
        dirPartyPostalAddressView.LocationName                  = 'Primary business';
        dirPartyPostalAddressView.Address                       = vendorRequestAddress.Addressing;
        dirPartyPostalAddressView.City                          = vendorRequestAddress.LogisticsAddressCity;
        dirPartyPostalAddressView.ZipCode                       = vendorRequestAddress.LogisticsAddressZipCodeId;
        dirPartyPostalAddressView.State                         = vendorRequestAddress.LogisticsAddressStateId;
        dirPartyPostalAddressView.Street                        = vendorRequestAddress.Addressing;
        //dirPartyPostalAddressView.Street                        = 'Dover Street';
        //dirPartyPostalAddressView.StreetNumber                  = '123';
        dirPartyPostalAddressView.CountryRegionId               = vendorRequestAddress.LogisticsAddressCountryRegionId;

        dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);
    }

}


4.
//Create communication details
public void createCommAddress(VendorRequestCreate          _vendorRequestCreate)
{

    VendorRequestCommunication       vendorRequestCommunication;
    ;

    select Phone1, Phone2, Email, Fax from vendorRequestCommunication
            where vendorRequestCommunication.WI_VendorRequestCreate == _vendorRequestCreate.RecId;

    //Phone 1
    if(vendorRequestCommunication.Phone1 != '' && vendTable.Party != 0)
    {
        logisticsLocation.clear();
        logisticsLocation   = LogisticsLocation::create('Phone', NoYes::No);

        dirPartyContactInfoView.LocationName                = 'Primay Phone 1';
        dirPartyContactInfoView.Locator                     = vendorRequestCommunication.Phone1;
        dirPartyContactInfoView.Type                        = LogisticsElectronicAddressMethodType::Phone;
        dirPartyContactInfoView.Party                       = vendTable.Party;
        dirPartyContactInfoView.IsPrimary                   = NoYes::Yes;
        dirParty.createOrUpdateContactInfo(dirPartyContactInfoView);
    }

    //Phone 2
    if(vendorRequestCommunication.Phone2 != '' && vendTable.Party != 0)
    {
        logisticsLocation.clear();
        logisticsLocation   = LogisticsLocation::create('Phone', NoYes::No);

        dirPartyContactInfoView.LocationName                = 'Primay Phone 2';
        dirPartyContactInfoView.Locator                     = vendorRequestCommunication.Phone2;
        dirPartyContactInfoView.Type                        = LogisticsElectronicAddressMethodType::Phone;
        dirPartyContactInfoView.Party                       = vendTable.Party;
        dirPartyContactInfoView.IsPrimary                   = NoYes::No;
        dirParty.createOrUpdateContactInfo(dirPartyContactInfoView);
    }

    //Email
    if(vendorRequestCommunication.Email != '' && vendTable.Party != 0)
    {
        logisticsLocation.clear();
        logisticsLocation   = LogisticsLocation::create('Phone', NoYes::No);

        dirPartyContactInfoView.LocationName                = 'Primay Email';
        dirPartyContactInfoView.Locator                     = vendorRequestCommunication.Email;
        dirPartyContactInfoView.Type                        = LogisticsElectronicAddressMethodType::Email;
        dirPartyContactInfoView.Party                       = vendTable.Party;
        dirPartyContactInfoView.IsPrimary                   = NoYes::Yes;
        dirParty.createOrUpdateContactInfo(dirPartyContactInfoView);
    }

    //Fax
    if(vendorRequestCommunication.Fax != '' && vendTable.Party != 0)
    {
        logisticsLocation.clear();
        logisticsLocation   = LogisticsLocation::create('Phone', NoYes::No);

        dirPartyContactInfoView.LocationName                = 'Primay Fax';
        dirPartyContactInfoView.Locator                     = vendorRequestCommunication.Fax;
        dirPartyContactInfoView.Type                        = LogisticsElectronicAddressMethodType::Fax;
        dirPartyContactInfoView.Party                       = vendTable.Party;
        dirPartyContactInfoView.IsPrimary                   = NoYes::Yes;
        dirParty.createOrUpdateContactInfo(dirPartyContactInfoView);
    }
}


5.
//Create bank details for the vendor
private void createBankDetails(WI_VendorRequestCreate          _vendorRequestCreate,
                               VendAccount                     _vendAcc)
{
    VendBankAccount         vendBankAccount;
    LogisticsLocation       lLogisticsLocation;
    LogisticsPostalAddress  logisticsPostalAddress;

    ;

    ttsBegin;

    lLogisticsLocation.Description      = _vendorRequestCreate.FirstName;
    lLogisticsLocation.insert();

    logisticsPostalAddress.Street       = _vendorRequestCreate.VendBankAddress;
    logisticsPostalAddress.Address      = _vendorRequestCreate.VendBankAddress;
    logisticsPostalAddress.Location     = lLogisticsLocation.RecId;
    logisticsPostalAddress.insert();

    vendBankAccount.AccountID           = subStr(_vendorRequestCreate.BankAccount,1,10);
    vendBankAccount.Name                = _vendorRequestCreate.BankAccount;
    vendBankAccount.AccountNum          = _vendorRequestCreate.BankAccountNum;
    vendBankAccount.VendAccount         = _vendAcc;
    vendBankAccount.CurrencyCode        = _vendorRequestCreate.CurrencyCode;
    vendBankAccount.BankGroupID         = BankAccountTable::find(vendBankAccount.AccountID).BankGroupId;
    vendBankAccount.Location            = lLogisticsLocation.RecId;
    vendBankAccount.WI_BeneficiaryName  = _vendorRequestCreate.BeneficiaryName;
    vendBankAccount.initFromBankGroup(BankGroup::find(vendBankAccount.BankGroupID));

    vendBankAccount.insert();
    ttsCommit;
}

6.
//Create contact for the vendor
private void createContact(VendorRequestCreate       _vendorRequestCreate,
                           RefRecId                     _partyId)
{
    ContactPerson           contactPerson;
    DirPersonName           lDirPersonName;
    DirPerson               lDirPerson;
    DirParty                lDirParty;
    LogisticsLocation       lLogisticsLocation;
    DirPartyContactInfoView             lDirPartyContactInfoView;
    ;

    //Create party for Contact
    lDirPerson.Name                          = _vendorRequestCreate.ContactPersonName;
    lDirPerson.NameAlias                     = _vendorRequestCreate.ContactPersonName;
    lDirPerson.NameSequence                  = dirNameSequence::find('First Last').RecId;
    lDirPerson.insert();

    lDirPersonName.FirstName                 = _vendorRequestCreate.ContactPersonName;
    //lDirPersonName.MiddleName                = _vendorRequestCreate.ContactPersonName;
    //lDirPersonName.LastName                  = _vendorRequestCreate.LastName;
    lDirPersonName.ValidFrom                 = DateTimeUtil::newDateTime(systemDateGet(),str2time ('00:00:00'),DateTimeUtil::getUserPreferredTimeZone());
    lDirPersonName.ValidTo                   = DateTimeUtil::maxValue();
    lDirPersonName.Person                    = lDirPerson.RecId;
    lDirPersonName.insert();

    lDirParty                                = new DirParty(lDirPerson);

    //Create contact and associate with party
    contactPerson.ContactForParty           = vendTable.Party;
    contactPerson.Party                     = lDirPerson.RecId;
    contactPerson.insert();

    //Create contact number
    if(_vendorRequestCreate.ContactPersonNo != '')
    {
        lLogisticsLocation.clear();
        lLogisticsLocation                  = LogisticsLocation::create('Phone', NoYes::No);

        lDirPartyContactInfoView.LocationName                = 'Primay Phone';
        lDirPartyContactInfoView.Locator                     = _vendorRequestCreate.ContactPersonNo;
        lDirPartyContactInfoView.Type                        = LogisticsElectronicAddressMethodType::Phone;
        lDirPartyContactInfoView.Party                       = contactPerson.Party;
        lDirPartyContactInfoView.IsPrimary                   = NoYes::Yes;
        lDirParty.createOrUpdateContactInfo(lDirPartyContactInfoView);
    }

}

13 comments:

  1. Have you tried using the VendorEntity class for creating vendors / Contacts / ECommunications? It handles the DirParty relationships with it,

    ReplyDelete
  2. Is your code complete? In function "createCommAddress" you create a LogisticsLocation record, but this record is newer used in your code!

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi....one question what is this "VendorRequestCreate"? My AX2012 System does not know this

    ReplyDelete
    Replies
    1. VendorRequestCreate is the table where u r saving the record temp till the time Vendor is created. Record buffer is passed to all classes to create the actual vendor.

      Delete
  5. You have done a brilliant job making sure that people understand where you are coming from. And let me tell you, I get it. Please post more updates to cure.
    postal address change online

    ReplyDelete
  6. i was once living on the street where by things were so hard for me, even to pay off my bills was very difficult for me i have to park off my apartment and start sleeping on the street of Vegas. i tried all i could do to secure a job but all went in vain because i was from the black side of America. so i decided to browse through on my phone for jobs online where i got an advert on Hackers advertising a Blank ATM card which can be used to hack any ATM Machine all over the world, i never thought this could be real because most advert on the internet are based on fraud, so i decided to give this a try and look where it will lead me to if it can change my life for good. i contacted this hackers and they told me they are from Australia and also they have branch all over the world in which they use in developing there ATM CARDS, this men who were geeks and also experts at ATM repairs, programming and execution who taught me various tips and tricks about breaking into an ATM Machine with a Blank ATM card.i applied for the Blank ATM card and it was delivered to me within 3 days and i did as i was told to and today my life has changed. there is no ATM MACHINES this BLANK ATM CARD CANNOT penetrate into, because it has been programmed with various tools and software before it will be send to you. i know this is illegal but also a smart way of living Big because the government cannot help us so we have to help our self. if you also want this BLANK ATM CARD you can contact these Hackers at
    email: skylinktechnes@yahoo.com whatsapp: +1(213)785-1553 or website: https://skylinktechnes.wixsite.com/info

    ReplyDelete
  7. Are you in a financial crisis, looking for money to start your own business or to pay your bills?
    GET YOUR BLANK ATM CREDIT CARD AT AFFORDABLE PRICE*
    We sell this cards to all our customers and interested buyers
    worldwide,Tho card has a daily withdrawal limit of $5000 and up to $50,000
    spending limit in stores and unlimited on POS.

    YOU CAN ALSO MAKE BINARY INVESTMENTS WITH LITTLE AS $500 AND GET $10,000 JUST IN SEVEN DAYS

    **WHAT WE OFFER**

    *1)WESTERN UNION TRANSFERS/MONEY GRAM TRANSFER*
    *2)BANKS LOGINS*
    *3)BANKS TRANSFERS*
    *4)CRYPTO CURRENCY MINNING*
    *5)BUYING OF GIFT CARDS*
    *6)LOADING OF ACCOUNTS*
    *7)WALMART TRANSFERS*
    *8)BITCOIN INVESTMENTS*
    *9)REMOVING OF NAME FROM DEBIT RECORD AND CRIMINAL RECORD*
    *10)BANK HACKING*
    **email blankatmmasterusa@gmail.com *
    **you can also call or whatsapp us Contact us today for more enlightenment *
    *+1(539) 888-2243*
    **BEWARE OF SCAMMERS AND FAKE HACKERS IMPERSONATING US BUT THEY ARE NOT
    FROM *
    *US CONTACT US ONLY VIA THIS CONTACT **
    *WE ARE REAL AND LEGIT...........

    2020 FUNDS/FORGET ABOUT GETTING A LOAN..*

    IT HAS BEEN TESTED AND TRUSTED

    ReplyDelete
  8. email: visacreditcardsolution@gmail.comGET YOUR BLANK ATM CREDIT CARD AT AFFORDABLE PRICE*
    **We sell these cards to all our customers and interested buyers
    worldwide,the card has a daily withdrawal limit of $5000 and up to $50,000
    spending limit in stores and unlimited on POS.**

    **WHAT WE OFFER**

    *1)WESTERN UNION TRANSFERS/MONEY GRAM TRANSFER*
    *2)BANKS LOGINS*
    *3)BANKS TRANSFERS*
    *4)CRYPTO CURRENCY MINNING*
    *5)BUYING OF GIFT CARDS*
    *6)LOADING OF ACCOUNTS*
    *7)WALMART TRANSFERS*
    *8)BITCOIN INVESTMENTS*
    *9)REMOVING OF NAME FROM DEBIT RECORD AND CRIMINAL RECORD*
    *10)BANK HACKING*

    ReplyDelete
  9. GET RICH WITH THE USE OF BLANK ATM CARD FROM
    (besthackersworld58@gmail.com)
    Has anyone here heard about blank ATM card? An ATM card that allows you to withdraw cash from any Atm machine in the world. No name required, no address required and no bank account required. The Atm card is already programmed to dispense cash from any Atm machine worldwide. I heard about this Atm card online but at first i didn't pay attention to it because everything seems too good to be true, but i was convinced & shocked when my friend at my place of work got the card from guarantee Atm card vendor. We both went to the ATM machine center and confirmed it really works, without delay i gave it a go. Ever since then I’ve been withdrawing $1,500 to $5000 daily from the blank ATM card & this card has really changed my life financially. I just bought an expensive car and am planning to get a house. For those interested in making quick money should contact them on: Email address : besthackersworld58@gmail.com or WhatsApp him on +1(323)-723-2568

    ReplyDelete