Translate

Thursday, June 28, 2012

Ledger journal import using x++

static void GLImport(Args _args)
{

    AxLedgerJournalTable        header = new AxLedgerJournalTable();
    AxLedgerJournalTrans        trans = new AxLedgerJournalTrans();
    container                   ledgerDim, offsetDim;
    LedgerJournalNameId         ledgerJournalNameId = "GeneralJR";
    DimensionAttributeValueCombination  ledgerDimension;
    LedgerJournalACType         accType, offsetAccType;
    BankAccountTable            bankAccountTable;

    ;
    accType         = LedgerJournalACType::Ledger;
    offsetAccType   = LedgerJournalACType::Bank;

    header.parmJournalName(ledgerJournalNameId);
    header.save();

    trans.parmAccountType(accType);
    trans.parmJournalNum(header.ledgerJournalTable().JournalNum);

    //If account type is Ledger
    ledgerDim = ["142102-C-ADMIN","142102","C","ADMIN"];//First is Display value, followed by Main Account and then dimensions.

    //If account type is other than ledger then Switch case statement can be written to get RecId from DimensionAttributeValueCombination Table.

    trans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(ledgerDim));
    trans.parmAmountCurDebit(230);
    trans.parmOffsetAccountType(offsetAccType);

    switch(offsetAccType)
    {
        case    LedgerJournalACType::Bank   :   select firstOnly bankAccountTable
                                                    join RecId from ledgerDimension
                                                        where ledgerDimension.DisplayValue      == bankAccountTable.AccountID
                                                        &&    bankAccountTable.AccountID        == "ICICI Bank";
                                                trans.parmOffsetLedgerDimension(ledgerDimension.RecId);

        //Same cases has to be written for others like Vendor, Customer. Except Account type ledger
        //If offset account type is ledger then trans.parmOffsetLedgerDimension() will only be supported.
    }

    //trans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(offsetDim));
    trans.save();

}


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

}

Product Information Management AX 2012

Hi All,

These days I have been a lot dealing with Products in AX 2012. In AX 2012 Inventory structure has been completely changed. So in brief we can understand the same as:


Understanding the Product structure:


Product type
·         Item type - This option will be selected if the product is an inventoried product
·         Service type - This option will be selected if the product is a non-inventoried product

Product sub type
·         Product master - Products of this sub-type must have a product dimension group that specifies the product dimensions that are active for the product (color, size, and configuration)
o    Configuration technology
§  Predefined variant - This type should be chosen if the product will not be configured, but simply rely on the user’s choice of Color, and/or Size, and/or Configuration for each transaction
§  Dimension-based configuration - This type should be chosen if the user will build a configurable BOM that relies on configuration rules to build the Config ID and the BOM lines. (This technology may only be chosen if Configuration is active on the Product dimension group selected for the product)
§  Rule-based configuration - This type should be chosen if the product will use Product builder
§  Constraint-based configuration - This type should be chosen if the product will use the new AX 2009 Constraint based product configuration method. (This technology may only be chosen if Configuration is active and is the lone Product dimension active for the Product dimension group selected for the product)
·         Product - Products of this sub-type do NOT have any product dimensions, and therefore do not have a product dimension group
·         Product variant - A large amount of information may be maintained at the Product master level, including, but not limited to:
o    Product dimensions
o    Images
o    Product categories
o    Product attributes
o   Unit conversions
For Product master products, Product dimensions and Product variants are extremely important. Both may be managed from menu items in the ribbons section of the Products form:

Dimensions
·         Product dimensions: Color, Size, Configuration
·         Storage dimensions: Site, Warehouse, Location, Pallet ID
·         Tracking dimensions: Batch number, Serial number

Release product
Once product variants have been created at the instance level, they must be released to individual companies before transactions may be performed in the respective company. Variants may be released from any of the Products forms (All, Distinct, Product masters), or from the Product variants form by clicking Release products in the ribbon section of the form. 

Tech part (Data model)
AX 2012 Item AIF Web Service (InventItemService) 
Table Name
Table Description
EcoResProduct
The EcoResProduct table stores products and is the base table in the products hierarchy.
EcoResProductMaster
The EcoResProductMaster table stores product masters.
EcoResProductIdentifier
The EcoResProductIdentifier table contains a product identification that is available for users.
EcoResDistinctProduct
The EcoResDistinctProduct table stores products.
EcoResDistinctProductVariant
The EcoResDistinctProductVariant table stores product variants.
EcoResProductDimensionGroup
The EcoResProductDimensionGroup table contains information about a dimension group.
EcoResProductDimensionGroupProduct
The EcoResProductDimensionGroupProduct table stores information about relationships between products and dimension groups.
EcoResColor
The EcoResColor table stores color names.
EcoResSize
The EcoResSize table stores size names.
EcoResConfiguration
The EcoResConfiguration table stores configuration names.
EcoResProductMasterColor
The EcoResProductMasterColor table stores information about colors assigned to product masters.
EcoResProductMasterSize
The EcoResProductMasterSize table stores information about sizes that are assigned to product masters.
EcoResProductMasterConfiguration
The EcoResProductMasterConfiguration table stores information about configurations assigned to product masters.
EcoResProductVariantColor
The EcoResProductVariantColor table stores information about the colors that are assigned to product variants.
EcoResProductVariantSize
The EcoResProductVariantSize table stores information about the sizes that are assigned to product variants.
EcoResProductVariantConfiguration
The EcoResProductVariantConfiguration table stores information about the configurations that are assigned to product variants.
EcoResProductMasterDimensionValue
The EcoResProductMasterDimensionValue table is the base table in the product model dimension hierarchy.
EcoResProductVariantDimensionValue
The EcoResProductVariantDimensionValue table is the base table in the product variant dimension hierarchy.
EcoResProductDimensionAttribute
The EcoResProductDimensionAttribute table contains definitions of product dimension attributes (categories).
EcoResInstanceValue
The EcoResInstanceValue table contains the definitions of the instances of the components or products.
EcoResProductInstanceValue
The EcoResProductInstanceValue table contains definitions of values for the instances of attributes of a product.
InventTable
The InventTable table contains information about items.
InventTableModule
The InventTableModule table contains information about purchase, sales, and inventory specific settings for items.
InventItemLocation
The InventItemLocation table contains information about items and the related warehouse and counting settings. The settings can be made specific based on the items configuration and vary from warehouse to warehouse.
InventItemSalesSetup
The InventItemSalesSetup table contains the default settings for items, such as site and warehouse. The values are related to sales settings.
InventItemInventSetup
The InventItemInventSetup table contains the default settings for items, such as site and warehouse. The values are related to inventory settings.
InventItemPurchSetup
The InventItemPurchSetup table contains the default settings for items, such as site and warehouse. The values are related to purchase settings.
InventItemSetupSupplyType
The InventItemSetupSupplyType table contains information about the sourcing of items.
InventDim
The InventDim table contains values for inventory dimensions.
InventDimCombination
The InventDimCombination table contains variants of items. The variants are created as product variants that are based on product dimensions such as size, color, and configuration. These variants are replicated to the legal entity.

For extended info use the below articles to import\integrate Products using AIF services. 

Cheers… J