Wednesday, 5 February 2014

Creating and posting a ledger voucher in ax 2012

1. Double-check that the getLedgerDimension() method exists in the
DimensionAttributeValueCombination table. If not, create it as described in the first
recipe in this chapter.
2. In the AOT, create a new job named LedgerVoucherPost with the following code:
static void LedgerVoucherPost(Args _args)
{
LedgerVoucher voucher;
LedgerVoucherObject voucherObj;
LedgerVoucherTransObject voucherTrObj1;
LedgerVoucherTransObject voucherTrObj2;
DimensionDynamicAccount ledgerDim;
DimensionDynamicAccount offsetLedgerDim;
CurrencyExchangeHelper currencyExchHelper;
CompanyInfo companyInfo;
ledgerDim =
DimensionAttributeValueCombination::getLedgerDimension(
'110180',
['Department', 'CostCenter', 'ExpensePurpose'],
['OU_2311', 'OU_3568', 'Training']);
offsetLedgerDim =
DimensionAttributeValueCombination::getLedgerDimension(
'170150',
['Department', 'CostCenter', 'ExpensePurpose'],
['OU_2311', 'OU_3568', 'Training']);
voucher = LedgerVoucher::newLedgerPost(DetailSummary::Detail,SysModule::Ledger,'');
voucherObj = LedgerVoucherObject::newVoucher('TEST00001');
companyInfo = CompanyInfo::findDataArea(curext());
currencyExchHelper = CurrencyExchangeHelper::newExchangeDate(
Ledger::primaryLedger(companyInfo.RecId),
voucherObj.parmAccountingDate());
voucher.addVoucher(voucherObj);
voucherTrObj1 =
LedgerVoucherTransObject::newTransactionAmountDefault(
voucherObj,
LedgerPostingType::LedgerJournal,
ledgerDim,
'USD',
1000,
currencyExchHelper);
voucherTrObj2 =
LedgerVoucherTransObject::newTransactionAmountDefault(
voucherObj,
LedgerPostingType::LedgerJournal,
offsetLedgerDim,
'USD',
-1000,
currencyExchHelper);
voucher.addTrans(voucherTrObj1);
voucher.addTrans(voucherTrObj2);
voucher.end();
info(strFmt(
"Voucher '%1' has been posted", voucher.lastVoucher()));
}

3. Run the class to create a new ledger voucher.
4. To check what has been posted, open General Ledger | Inquiries | Voucher
transactions and type in the voucher number used in the code:

5. Click on OK to display the posted voucher:

Saturday, 1 February 2014

Install Microsoft Dynamics AX on local system without Domain

First, Go to System Properties > Advanced Tab > Environment Variables > System Variables then click New.
Put "UserDnsDomain" on the Variable name. Put any value on the variable value.
run Registry Editor or regedit. go to
Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName
put any value on the value data.
Install AX.
Note: After Installing AX, change your ActiveComputerName in the Registry to your default computer name. Use the Computer Name in installing the AOS (computer name before changing the registry.)
then restart.

Creating Bootable Pen Drive Using Windows Command Prompt

Making a pen drive bootable is possible in Windows7 & Windows8 operating system. Formatting a computer to install fresh Windows OS with a CD/DVD drive is not very good because it takes too much time to install fresh Windows operating system. There can also be a problem for many people that CD/DVD drive doesn’t work properly. So this can be a problem for them. Today laptop or desktop comes many USB ports. So there is no need of CD/DVD drive to format a system. Formatting is very fast and easy with flash drive/pen drive and also no software is required for this method. Windows7 or Windows8 command prompt can do the work with few lines of command. Just follow this tutorial.
Start your command prompt.
 For windows7 users:
Go to “Start” button and click. Write “cmd” then cmd icon will appear on the top of the panel. (Fig.1)
Starting Windows CMD
Fig.1-Starting Windows CMD
“Right click” on the cmd icon and click “Run as administrator”(Fig.2)

Running Command Prompt As Administrative
Fig.2-Running Command Prompt As Administrative
It will open the command prompt. (Fig.3)
Windows 7 CMD Window Pops Up
Fig.3-Windows 7 CMD Window Pops Up
For windows 8 users:
Press “Windows key” and press “c”. You will see the command prompt icon. “Right click” on the command prompt icon and click “Run as administrator” from the bottom bar. (Fig.4)
Windows 8 CMD Window Pops Up
Fig.4-Windows 8 CMD Window Pops Up
It will open the command prompt like in Fig.3
Now following steps are same for the windows7 and 8 OS.
Type “diskpart” inside the command prompt and hit “ENTER”(Fig.5)
Type diskpart And Enter
Fig.5-Type diskpart And Enter
It will good before going to next step that you should disconnect all other external hard disk, flash/pen drive etc. because accidently these drive can be formatted. So taking precaution is good. Only one pen drive with minimum 4 GB should be connected. Save all the data from the pen drive because it will be formatted in one of the following step.
After last step type “list disk” inside the command prompt and hit “ENTER”(Fig.6)
Type list Disk And Enter
Fig.6-Type list Disk And Enter
This will show all disk connected to the system like DISK 0, Disk 1, and so on with “Status”, “Size” , “Free” etc.. We can recognize the pen drive with size. Disk 0 will be the system disk in which the windows OS is installed. In this tutorial Disk 1 is the pen drive (3855MB=4GB). This pen drive is going to be a bootable pen drive.
Type “select disk 1” inside the command prompt and hit “ENTER”. It will select the disk 1 (pen drive) for all coming steps. (Fig.7)

Type select Disk 1 And Enter
Fig.7-Type select Disk 1 And Enter
Type “clean” and hit “ENTER”. It will erase all the data from the pen drive. (Fig.8)
Type clean And Enter
Fig.8-Type clean And Enter
Type “create partition primary” and hit “ENTER”. It will create a primary partition in pen drive. (Fig.9)
Type create partition primary And Enter
Fig.9-Type create partition primary And Enter
Type “select partition 1” and hit “ENTER”. It will select the partition created in the last step. (Fig.10)
Type select partition 1 And Enter
Fig.10-Type select partition 1 And Enter
Type “format=fs ntfs quick” and hit “ENTER”. It will format the pen drive quickly with NTFS file type. (Fig.11)
Type format=fs quick And Enter
Fig.11-Type format=fs quick And Enter
Type “active” and hit “ENTER”. It will make partition as active for booting after restarting the computer. If this is step is missed then computer will not boot from the pen drive. (Fig.12)
Type active And Enter
Fig.12-Type active And Enter
Type “exit ” and hit “ENTER” to close the diskpart and close the command prompt window. (Fig.13)

Type exit And Enter
Fig.13-Type exit And Enter
Now the pen drive has become bootable. Now all the files from root of Windows operating system setup DVD or ISO has to copy inside the pen drive root.
So open the Windows setup file from DVD or ISO and copy all file by selecting with “Ctrl+A” and paste it inside the pen drive’s root folder as shown in the figure. (Fig.14)
Copying All Files And Pasting It
Fig.14-Copying All Files And Pasting It
After complete copy, the pen drive will be a bootable for Windows 7 and Windows 8 OS completely. You just need to“Restart” your computer. “Restart” your computer. When BIOS screen appears then press “F12” key. It will show the options to boot from CD/DVD drivehard disk and pen drive. Just scroll down to pen drive and hit “Enter”. Your system will boot from pen drive. Now you can install windows OS.
http://www.wikihow.com/Create-a-Bootable-Windows-7-or-Vista-USB-Drive

Friday, 31 January 2014

what is difference between unique index and primary index

Primary Key uniquely identifies the record and the 
UNIQUE index on the primary key ensures that no duplicates values will be stored in the table
1)Primary key creates an implicit clustered index on a table, 
  unique key does not create any implicit index.

2)Columns defined as primary key does not allow null values,
where as columns defined as unique can allow null values.

3)A table can have just one primary key (can be a composite key) 
where as there can be multiple unique columns (keys).

4)Primary key is a unique key with the above mentioned features
http://msdn.microsoft.com/en-us/library/aa656402.aspx

Tuesday, 28 January 2014

Classes, Tables, Forms and Methods used to post the sales orders in ax 2009

Classes, Tables, Forms and Methods used to post the sales orders

SalesTableType and SaleslineType classes will get called while creating the orders.
SalesFormLetter* classes will be used to post the sales order at various document status(packing, invoice etc).
SalesParm* tables are used to prepare the data for posting
CustConfirmJour, CustConfirmTrans - when a sales order gets confirmed
CustPackingSlipJour, CustPackingSlipTrans - when a packing slip is posted.
CustInvoiceTable,CustInvoiceTrans - when an invoice is posted.
These are some of the maily used tables.

public class FormRun extends ObjectRun
{
    SalesFormLetter_Confirm salesFormLetter_Confirm;
    SalesFormLetter_Invoice salesFormLetter_Invoice;
    SalesFormLetter_PackingSlip salesFormLetter_PackingSlip;
    SalesFormLetter_PickingList salesFormLetter_PickingList;
}

// when you click

void clicked()
{
    SalesTable salesTable;

    if(SalesId.valueStr()!="")
    {

        salesTable = SalesTable::find(SalesId.valueStr(), true);// retrives the sales id based on the slected sales id on text box;

    if(ActionType.valueStr() == enum2str(SalesOrderType::Confirm)) // if Sales order type is confirm
    {
        if(salesTable.DocumentStatus != DocumentStatus::None)// if sales order is confirmed, other wise else part
        {
            info(strFmt("@MAD39",salesTable.SalesId));

        }
        else
        {
            salesFormLetter_Confirm =SalesFormLetter::construct(DocumentStatus::Confirmation);
            salesFormLetter_Confirm.update(salesTable, SystemDateGet(), SalesUpdate::All,AccountOrder::None,false,false );
            info(strFmt("@MAD41",salesTable.SalesId));
        }
    }
    else
        if(ActionType.valueStr() == enum2str(SalesOrderType::Invoice)) // if saler order type is invoice
        {
            if(salesTable.SalesStatus == SalesStatus::Invoiced) // if sales order is invoiced ,other wise elese part.
            {
            info(strFmt("@MAD37",salesTable.SalesId));
            }
            else
            {
            salesFormLetter_Invoice =SalesFormLetter::construct(DocumentStatus::Invoice);
            salesFormLetter_Invoice.update(salesTable, SystemDateGet(), SalesUpdate::All,AccountOrder::None,false,false );

            info(strFmt("@MAD43",salesTable.SalesId));
            }
    }
    else
        if(ActionType.valueStr() == enum2str(SalesOrderType::PackingSlip)) // if sales order type is packing slip
        {
            if(salesTable.SalesStatus == SalesStatus::Delivered) // if packing slip is done for the saler order, other wise else part
            {
            info(strFmt("@MAD38",salesTable.SalesId));
            }
            else
            {
            salesFormLetter_PackingSlip =SalesFormLetter::construct(DocumentStatus::PackingSlip);
            salesFormLetter_PackingSlip.update(salesTable, SystemDateGet(), SalesUpdate::All,AccountOrder::None,false,false );
            info(strFmt("@MAD44",salesTable.SalesId));
            }
        }
    else
        if(actiontype.valuestr() == enum2str(salesordertype::pickinglist)) // if sales order type is picking list
        {
            if(salestable.salesstatus == salesstatus::delivered) // if picking list is done for the sales order , other wise elese part.
            {
            info(strfmt("@mad40",salestable.salesid));
            }
            else
            {
                salesformletter_pickinglist =salesformletter::construct(documentstatus::pickinglist);
                salesformletter_pickinglist.update(salestable, systemdateget(), salesupdate::PickingList,accountorder::none,false,false );
                info(strfmt("@mad45",salestable.salesid));
            }
        }
    }
    else
    {
        Box::stop("@MAD47","@SYS8500");
    }

    super();
}

Monday, 27 January 2014

Microsoft Dynamics AX2012 Import-AXModelStore


The suggested method for deploying Dynamics AX2012 code into production environment (Eg. Go live) is to import the model store.
Read more about the difference between model and model store at this link: http://technet.microsoft.com/en-us/library/hh335184.aspx
Compare AX4, AX2009 and AX2012 deployment:
- AX4, AX2009: Copy layer and label files, replace the destination files (in application folder)
- AX2012: Export model store and import model store
There’re two ways to import model store:
1. Using PowerShell
2. Using AXUtil.exe

The rest of the text below will use PowerShell as the AXUtil will be obsolete in future version of Dynamics AX.
Start Dynamics AX PowerShell from here: All Programs > Administrative Tools > Microsoft Dynamics AX Management Shell
The steps:
1.             Export model store from your source (Eg. UAT environment)
(Similar to AX2009 copy layer & label files)
- Export model store
  
2.             Import model store to destination (Eg. Production environment)
(Similar to AX2009 replace layer & label files)
- Create a temporary schema
- Import model store to temporary schema
- Apply the model store

Export model store
Export model store is quite straight forward.
Syntax: Export-AXModelStore -File <filename> -Details
Eg. Export-AXModelStore -File “UAT.axmodelstore” –Details

What happen behind the scene?
The Export-AXModelStore connect to SQL server and access the AX database, then select and save the data into file (with the file name you specified in the command).

It gets the database name from AX server (AOS) configuration.
 
 

Export-AXModelStore with file name "STD_ModelStore"


Import model store

Create a temporary schema
Create a temporary schema in AX database to be used on next step during import model store.

Steps:
1. Open SQL Server Management Studio
2. Connect to the SQL Server instance where AX database resides
3. Expand to Databases > [AxDatabaseName] > Security > Schemas
4. Right click > New schema
5. Type in the temporary schema name (Eg. TempSchema) and select the schema owner and click "OK"
6. Initialize the temporary schema (Eg. Initialize-AXModelStore -AOSAccount "Domain\AccountName" -SchemaName <NewSchema> -Server <ServerName> -Database <DatabaseName>)

Import model store to temporary schema
Syntax: Import-AXModelStore -File <filename> -SchemaName 
Eg. Import-AXModelStore -File UAT.axmodelstore -SchemaName TempSchema

What happen behind the scene?
The Import-AXModelStore read the *.axmodelstore file and do bulk insert.
It uses .NET SqlBulkCopy class and through TDS (Tabular Data Stream) pushing the data into AX model store tables.

You’ll see the command in SQL server like this: insert bulk [TempSchema].[ModelElementData] ([LayerId] Int, [ParentHandle] Int, [ElementHandle] Int, [LegacyId] Int, [Properties] VarBinary(max), [FileHeader] VarBinary(max), [BASEVERSION] Int, [VERSION] Int, [SAVECOUNT] Int, [CONSISTENCYDATA] Int, [MODIFIEDDATETIME] DateTime, [MODIFIEDBY] NVarChar(5) COLLATE SQL_Latin1_General_CP1_CI_AS, [CREATEDDATETIME] DateTime, [CREATEDBY] NVarChar(5) COLLATE SQL_Latin1_General_CP1_CI_AS, [ElementVersion] Int, [ModelId] Int) with (TABLOCK)

This "INSERT BULK" is different than the "BULK INSERT", it can’t be used in SQL server directly, it has to go through API.

Import-AXModelStore with file name "UAT.axmodelstore" and schema "TempSchema"
Apply the model store
Syntax: Import-AXModelStore -Apply:TemporarySchema
Eg: Import-AXModelStore -Apply:TempSchema

What happen behind the scene?
It execute several stored procedures to transfer the temporary schema to default.
Eg.
- XU_IsSchemaEmpty
- XU_CreateSchema
- XU_TransferObjectsToSchema
and etc

Apply model store (Import-AXModelStore -Apply) with the temporary schema imported earlier

You doesn't need to manually remove the temporary schema after apply it as they won't remain in the AX database after the APPLY process.

But if you decided not to apply the model store, you can remove it with the following syntax.
Syntax: Initialize-AXModelStore –Drop 
Eg: Initialize-AXModelStore –Drop TempSchema

Alternative
If you prefer to directly import the model store into default schema and replace it, do remember when it hit ID conflict, the import will stop.

For more details about working on model store, visit this link:
http://technet.microsoft.com/en-us/library/hh433530.aspx
http://technet.microsoft.com/en-us/library/hh433540.aspx

Misc. screenshot during my test

Create AX model store (Initialize-AXModelStore)

Import-AXModelstore error due to database referred in AOS settings does not exist


Initialize-AXModelStore error on pre-release AX2012 database due to stored procedure - "XU_DropSchema" does not exist


Import-AXModelStore error when schema does not exist


Import-AXModelStore error when Id conflict detected
  

Apply AX model store (Import-AXModelStore -Apply) error when applying the RTM model store to pre-release AX database due to XU_CreateSchema does not exist in pre-release database


Apply AX model store (Import-AXModelStore -Apply) error when applying the RTM model store to pre-release AX database due to pre-release database stored proc is outdated, has different number of parameters
 

Some of the tables created using Initialize-AXModelStore (to get the full list, you can query the list of objects attached to the schema you created through the Initialize-AXModelStore)