Tuesday, December 16, 2014

Update the Cubes in dynamics AX 2012 using Visual Studio

Following steps will illustrate the way to update the analysis project cubes via visual studio framework.

1- Open the Microsoft Dynamics development AX client.
2- Click Tools > Business Intelligence (BI) tools > SQL Server Analysis Services project wizard.



3- On the Analysis Services project wizard page, click Next



4- On the Select an option page, click Update, and then click next.

5- On the Select an existing Analysis Services project page, Select Dynamics AX (or the other project you want to update) from the AOT, and then click next.

  
6- On the Verifying the SQL Server Analysis Service Project page, click Next.


7- On select perspectives Cubes and dimensions page, select all cubes, perspectives and dimension and click Next.


8- Then select all measure groups and click Next.


9- Then select Date dimension and click Next.


10- Select the language option English(United State) and click Next.


11- Checked the foreign currency option and click Next, as shown below.



12- On the Confirm changes page, click Next



13- On the Deployment option page, click Cancel as shown below. (Don’t deploy the project from here, we will use visual studio for this.)


14- Right click Dynamics AX analysis project and select edit to open it the project in Visual studio. (for this visual studio development tool must be installed in Ax).



15- When the Visual Studio get open, before doing anything make sure you are connected with the correct server and database. To confirm this Right Click Dynamics AX node and click properties option. See screenshot.


16- Now make sure that you are connected with correct database (or change it accordingly), for this double clicked on                  Data Sources -> Dynamics Database


17- Now the purchcube is ready to deploy and process. Right click on purchcube and select process option. The system may appear the below message, click Yes.


18- When you click “Yes” the system may again appear with the new message before overwriting the database. Click “Yes” to continue.


19- The final message will appear when the cube gets deployed, you will be required to click on “Run” option to process the cube.



          Hope this will be helpful.

Wednesday, December 3, 2014

Create purchase order and generate invoice in Dynamics AX.

To create new purchase order, you need to follow these steps.

  1. click Accounts payable -> Purchase order -> All purchase orders

  1. You will get the below screen, then click "Purchase order".



  1. Now select Vendor account and set the site and warehouse location under storage dimension as shown below.




  1. As you will click the "ok" button on previous form, you will be redirect to the next form to select the order Line. To add multiple line click "Add line" option under purchase order lines grid.




  1. Once you have created the lines, you need to confirm the purchase order. For this you be required to click "Purchase" menu (on the top of the form) then you will find the "confirm" option in Generate group as shown below screenshot.



  1. After purchase order confirmation, you will be required to create the product receipt. For this click on "Receive"  -> "Product receipt" option (from top of the form menu). After that you will get the below screen where you will be required to enter the "Product receipt" no. (you can enter the dummy no. for testing, here I have enter  4458) then click OK.



  1. So far now the purchase order has been generated, now to create purchase invoice navigate to "Invoice" -> "Invoice" as shown below screenshot.





  1. Finally you will be required to post that invoice click "Post" -> "post" (button). Make sure you check the print invoice checkbox to get the invoice report.



  1. Finally, here is the invoice report of your purchase order.



Monday, October 20, 2014

Errors occurred while processing the Analysis Services OLE DB or ODBC error Login failed


OLE DB error: OLE DB or ODBC error: Login failed for user domain\username; 28000; Cannot open database "Ax2012Contoso" requested by the login. The login failed.; 42000.

Errors in the high-level relational engine. A connection could not be made to the data source with the DataSourceID of ‘Dynamics Database’, Name of ‘Dynamics Database’.

Internal error: The operation terminated unsuccessfully.

Server: The operation has been cancelled.

If this kind of error appeared while deploying the Analysis Cube. Follow these steps.

1-  Make sure "SQL Server Analysis Services (MSSQLSERVER)" service is running with the same  account as with "Microsoft Dynamics AX Object Serve" service is running.

2- The account under  "SQL Server Analysis Services (MSSQLSERVER)" service is running should the sufficient right to access warehouse data.

To resolve this you have to give at least db_datareader to the user that the Analysis Services Service is running as on the data warehouse.

To add user rights to the data warehouse:

· Open SQL Server Management Studio.
· Expand the Security node, Expand Logins, if the username from the error message above exists in the list, right click and Properties. Otherwise right click Logins, "New Login…" and type in the correct Login Name:

· On the "User Mapping" tab check the data warehouse Map checkbox and select db_datareader for it.

Friday, September 26, 2014

Create Purchase Order And Post Invoice via X++

Following is X++ code to create purchase order and post the invoice using PurchFormLetter class.

static void CreatePOAndInvoice(Args _args)
{
    PurchTable      purchTable;
    PurchLine       purchLine;
    VendTable       vendTable = VendTable::find("1005");
    AxPurchTable    axPurchTable;
    AxPurchLine     axPurchLine;
    PurchFormLetter purchFormLetter;


    //update site and warehouse locations.
    vendTable.InventSiteId ='DC';
    vendTable.InventLocation = 'TW';
 
 
    //Create Purchase order
    purchTable.initFromVendTable(vendTable);

    axPurchTable = axPurchTable::newPurchTable(purchTable);
    axPurchTable.parmPurchaseType(PurchaseType::Purch);
    axPurchTable.parmDocumentStatus(DocumentStatus::PurchaseOrder);
    axPurchTable.parmAccountingDate(systemDateGet());
    axPurchTable.parmDeliveryDate(01\06\2012);
    axPurchTable.parmPurchStatus(PurchStatus::Backorder);
    axPurchTable.doSave();

    //Create PurchLine for item 1000
    purchLine.initFromPurchTable(purchTable);

    axPurchLine = AxPurchLine::newPurchLine(purchLine);

    axpurchLine.parmItemId("0002");
    axPurchLine.parmPurchQty(10);
    axPurchLine.parmPurchPrice(100);
    axPurchLine.doSave();

    //Posting PO Confirmation,I guess its mandatory
    //You cannot do invoice without doing PO confirm
    purchTable = axPurchTable.purchTable();
    purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
    purchFormLetter.update(purchTable, strFmt("Inv_%1", purchTable.PurchId));

    //Posting PO Invoice
    purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);
    purchFormLetter.update(purchTable, strFmt("Inv_%1", purchTable.PurchId));

    info('Done.');
}

Monday, September 15, 2014

Create Sale Order using AIF service AX2012


SalesSalesOrderService will be required to place sales order. it is predefined service in AX2012. you will just need to perform following steps.

1-  Register Service (right click on service -->Add-In -->Register Service) and .

2-  System Administration --> Inbound ports -->{Add new salesorder service}

On c# create salesorder like this.

3-  Create c# web service project and add service reference 'SalesOrderServiceRef'

4-  public static void CreateSalesOrder()
        {
            var line = new AxdEntity_SalesLine()
            {
                ItemId = "0019",
                SalesQty = 42,
                SalesUnit = "ea"
            };
           
            var order = new AxdEntity_SalesTable()
            {
                CustAccount = "100001",
                PurchOrderFormNum = "xyz",
                ReceiptDateRequested = DateTime.Now.Date,
                SalesLine = new AxdEntity_SalesLine[] { line }
            };

            var orderList = new AxdEntity_SalesTable[] { order };
            var callContext = new CallContext() { Company = "USRT" };
            var client = new SalesOrderServiceClient();

            AxdSalesOrder o = new AxdSalesOrder();
            o.SalesTable = orderList;
            try
            {
                client.create(callContext, o);
                client.Close();
            }
            catch
            {
                client.Abort();
                throw;
            }
        }

Wednesday, August 27, 2014

FormLetter Framework

The formletter framework in Microsoft Dynamics AX is used when posting documents for sales or purchase orders. The framework has been refactored in Microsoft Dynamics AX 2012 to provide better support for customizations, extensibility, and performance.

If you have to create new custom field in Purchase order and required
flow it to all table as FormLetter work. Follow these steps.

Create new field let say 'Remarks' in following tables.

  1. PurchTable
  2. VendInvoiceInfoTable
  3. VendInvoiceJour
  4. PurchParmTable

Add an assignment for your new field in  VendInvoiceJour Table Method 'initFromPurchTable'

this.Remarks                = PurchTable.Remarks;


Now create abstract class in AXVendDocumentTableMap class

public abstract Name parmRemarks(Name _remarks = '')
{
}

After this you will need to create two method in VendDocumentTableType classs
As shown below.

protected Name determineDefaultRemarks()
{
    Name remarks;


    remarks = this.purchTable().Remarks;

    return remarks;
}

protected void defaultRemarks()
{
    Name remarks;
    ;

    if (!this.axVendDocumentTableMap().isTableFieldSet(fieldnum(VendDocumentTableMap, Remarks)))
    {
        remarks = this.determineDefaultRemarks();
        this.axVendDocumentTableMap().parmRemarks(remarks);
    }
}

Now register new field in 'VendDocumentTableMap' TableMap  and create its mapping in PurchParmTable and VendInvoiceInfoTable.

Finally add an assignment in PurchFormLetterParmData class as shown below.

parmTable.Remarks= localPurchTable.Remarks;


Wednesday, August 20, 2014

Unit Of Work Implementation in Dynamics AX

Unit of Work is a new framework , which is being introduced in AX 2012.
It is use to commit number of records in a single Transaction.The main reason for introducing unit of work is that it is impossible to insert the lines table record before its header table  because there is a relation between the header table and the lines table.The Recid of the header table is comes as a foreign key in the child table.

Now we dont have to hold the recid of parent table and also we can insert all data in a single trip . How., Let us Implement this :

  1. Create 2 table SKUHeader and SKULine.
  2. SKULine is related to SKUHeader by RecId.
  3. Go to relation of table and make sure property CreateNavigationPropertyMethods = True by making this property true , system will add appropriate methods to table SKULine
  4. create a class as shown blow.
         public class SKUUnitOfWork
            {
               }
         
          5. Now create a method, remember UnitofWork will always used on server
      public server static void main(Args args)
      {
          SKUHeader                      skuHeader;
          SKULine                        skuLine;

          int                            mycount;
          int                            mycount2;

          UnitofWork unitofWork = new UnitofWork();

          for(mycount=0; mycount<10; mycount++)
          {
           //insert data in parent table
              skuHeader.clear();
              skuHeader.GroupName = 'ProductGroup_' + int2str(mycount+1);
              unitofWork.insertonSaveChanges(skuHeader);

              for(mycount2=0; mycount2<10; mycount2++)
              {
                  //insert data in child table
                  skuLine.clear();
                  skuLine.ProductName = 'Product_' + int2str(mycount2+1);
                  skuLine.ProductPrice = int2str(mycount2+1 * 5);
                  skuLine.SKUHeader(skuHeader);
                  unitofWork.insertonSaveChanges(skuLine);
              }
          }
          //Now insert data in a single trip
          unitofWork.saveChanges();

          info('Done');
      }


          6. Finally generate a action type menuItem for SKUUnitOfWork class.

      you have done. as you will execute menuItem it will call the main method of the class.
      see complete snapshot.