Friday, June 3, 2016

How to change the value of a default dimension of a record in AX 2012

The following job will give you an example, of how to change the value of a dimension within the default dimensions of a record (the example-job changes the value of the dimension costcenterof a customer). In this way and manner individual dimension values can be removed also.

static void changeDimensionValue(Args _args)
{
    DimensionAttributeValueSetStorage dimensionAttributeValueSetStorage;
    DimensionAttribute dimensionAttribute;
    CustTable custTable = CustTable::find("US-014");
    DimensionValue oldDimensionValue;
    DimensionValue newDimensionValue = "011";
    DimensionDefault newDimensionDefault;

    #define.dimensionName("CostCenter")

    DimensionValue getDimensonValue(DimensionDefault _dimensionDefault)
    {
        DefaultDimensionView defaultDimensionView;
        select firstonly DisplayValue
        from defaultDimensionView
        where defaultDimensionView.Name == #dimensionName
            && defaultDimensionView.DefaultDimension == _dimensionDefault;

        return defaultDimensionView.DisplayValue;
    }

    // Get current value
    oldDimensionValue = getDimensonValue(custTable.DefaultDimension);

    // Build DimensionAttributeValueSetStorage
    dimensionAttributeValueSetStorage = DimensionAttributeValueSetStorage::find(custTable.DefaultDimension);
 
    // Remove old dimension value
    dimensionAttribute = DimensionAttribute::findByName(#dimensionName);
    dimensionAttributeValueSetStorage.removeDimensionAttributeValue(
        DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, oldDimensionValue).RecId);
 
    // Set new dimension value
    if(newDimensionValue != "")
    {
        dimensionAttribute = DimensionAttribute::findByName(#dimensionName);
        dimensionAttributeValueSetStorage.addItem(
            DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, newDimensionValue));
    }
 
    newDimensionDefault = dimensionAttributeValueSetStorage.save();

    ttsbegin;
    custTable.selectForUpdate(true);
    custTable.DefaultDimension = newDimensionDefault;
    custTable.update();
    ttscommit;

}

Thursday, August 6, 2015

Dynamics AX excel data import

I found very nice precise blog about excel imports for customer, vendors, transactions, GL products etc:


Happy Daxing !!!


 

Saturday, May 30, 2015

DMF Error on import the data into staging table: Exception from HRESULT: 0xC0048021 at Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelper.DMFEntity.ShowPreview(Boolean isComposite)

I have been trying to import data from an Excel file using Data Import Export Framework. The mapping and validation works but when I try to import the data into staging table – I get the below error:

Exception from HRESULT: 0xC0048021  at Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelper.DMFEntity.ShowPreview(Boolean isComposite)  at Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelperService.Service.ServiceHelper.ShowPreview(DMFEntity entity)

Error:
Exception from HRESULT: 0xC0048021
at Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelper.DMFEntity.ShowPreview(Boolean isComposite)
at Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelperService.Service.ServiceHelper.ShowPreview(DMFEntity entity)

Solution:

The problem is caused by the DMConfig XML file.
Go to the DMConfig.xml file in the “C:\Program Files\Microsoft Dynamics AX\60\DataImportExportFramework” folder and replace the PipelineComponentInfo_Multicast, PipelineComponentInfo_ExcelSource and   nodes by the following:

    {33D831DE-5DCF-48F0-B431-4D327B9E785D}
 
 
    {9F5C585F-2F02-4622-B273-F75D52419D4A}
 
 
    {90E2E609-1207-4CB0-A8CE-CC7B8CFE2510}
 

Happy Daxing !!!!


Thursday, March 19, 2015

CompanyInfo VatNum or any other field Unretrieved issue

Recently I came across one strange issue related to Service Order > Worker description report, I got exception every time when I run this report, after doing some investigation I found that the VatNum field is used in DP class but when i open CompanyInfo table from AOT, I got 'Unretrieved' values of this VatNum for all rows. VatNum basically a string field and it should be either BLANK or having some values. After trying so many trick from google (restart AOS, refresh cache) i still got the 'Unretrieved' issue. I than decided to set this field explicitly from backend DB, in Dynamics AX 2012 R2 databases, it appears that the CompanyInfo table (for example) exists in the AOT but not in the actual SQL database. The columns & data that are supposedly contained in CompanyInfo (according to the AOT) are actually found in the DirPartyTable. This is in contrast to AX 2012 databases. So after manually delete 'NULL' value from VATNum on DirPartyTable to BLANK i than able to run the report successfully. So TWO key point here are :
  • To overcome the 'Unretrieved' issue you can directly replace column value from NULL to BLANK.
  • You can find CompanyInfo table in AOT but not from SQL DB, use DirPartyTable instead to fix your desired 'Unretrieved' field issue.

Happy DAXing !!!!

Thursday, November 27, 2014

Copy Custom field from PO line to Invoice line

Sometime we have a scenario where we have to copy custom field value from PO to invoice, to do this you have create similar field in VendInvoiceInfoLine table and set/copy the value from PO line to invoice line on VendInvoiceInfoLine.defaultRaw() method or in class VendDocumentLineType_Invoice.

Happy DAXing !!!!

Monday, November 24, 2014

Add Action pane AxActionPaneControl to EP form

To add Action pane with default Save and Close buttons, here are the steps:

Create two web menus in AX
Add following code on ASP.NET script:
<%@ Register Assembly="Microsoft.Dynamics.Framework.Portal, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
 Namespace="Microsoft.Dynamics.Framework.Portal.UI.WebControls" TagPrefix="dynamics" %>
<%@ Register Src="AxBaseUserControl.ascx" TagName="AxBaseUserControl" TagPrefix="Ax" %>
<%@ Register Assembly="Microsoft.Dynamics.Framework.Portal.SharePoint, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="Microsoft.Dynamics.Framework.Portal.SharePoint.UI.WebControls" TagPrefix="dynamics" %>

dynamics:AxDataSource ID="youDS" runat="server" DataSetName="youDS"
    ProviderView="yourTable">
dynamics:AxDataSource

dynamics:AxActionPaneControl ID="AxActionPaneControlTop" runat="server"
DataMember="yourDS_Current" DataSourceID="yourDS"
WebMenuName="axToolBarInfo" EnableMenuItemHelpText="True" EnableTheming="True"
dynamics:AxActionPaneControl ID="AxActionPaneControlEdit" runat="server" EnableTheming="True"
DataMember="youDS_Current" DataSourceID="youDS" EnableMenuItemHelpText="True" WebMenuName="axToolBarCreate"

Now write following code in C# code behind:

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Dynamics.Framework.Portal.UI;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls;
using Microsoft.Dynamics.AX.Framework.Services.Client;
using Microsoft.Dynamics.AX.Framework.Portal.Data;
using Proxy = Microsoft.Dynamics.Framework.BusinessConnector.Proxy;
using ApplicationProxy = Microsoft.Dynamics.Portal.Application.Proxy;
using Microsoft.Dynamics.Framework.BusinessConnector.Adapter;
using Microsoft.Dynamics.Framework.Portal;
using Microsoft.Dynamics.Portal.Application.Proxy;
using Microsoft.Dynamics.Framework.BusinessConnector.Session;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls.WebParts;

public partial class Form1: System.Web.UI.UserControl
{
    protected const string axToolbar_Info = "axtoolbarinfo";
    protected const string axtoolbar_Create = "axtoolbarcreate";
    private const string MENU_ITEM_SaveAndClose = "epsaveandclose";
    private const string MENU_ITEM_Close = "epclose";

    protected void Page_Load(object sender, EventArgs e)
    {
        this.SetupMode();
    }

    void Page_Init(object sender, EventArgs e)
    {
        this.AxActionPaneControlTop.SetMenuItemProperties += new EventHandler(AxActionPaneControlTop_SetMenuItemProperties);
        this.AxActionPaneControlTop.ActionMenuItemClicking += new EventHandler(AxActionPaneControlTop_ActionMenuItemClicking);
        this.AxActionPaneControlTop.ActionMenuItemClicked += new EventHandler(AxActionPaneControl_ActionMenuItemClicked);

        this.AxActionPaneControlEdit.SetMenuItemProperties += new EventHandler(AxActionPaneControlTop_SetMenuItemProperties);
        this.AxActionPaneControlEdit.ActionMenuItemClicking += new EventHandler(AxActionPaneControlTop_ActionMenuItemClicking);
        this.AxActionPaneControlEdit.ActionMenuItemClicked += new EventHandler(AxActionPaneControl_ActionMenuItemClicked);
    }
    ApplicationProxy.EPFormAction FormMode
    {
        get
        {
            return (ApplicationProxy.EPFormAction)Convert.ToInt16(
            this.Page.Request.QueryString.Get("mode")); // This mode is the param set in web menu item url, i.e. mode=1
        }
    }

    private ISession AxSession
    {
        get
        {
            AxBaseWebPart webpart = AxBaseWebPart.GetWebpart(this);
            return webpart == null ? null : webpart.Session;
        }
    }

    private void SetupMode()
    {
        //Proxy.Info objInfoLog = new Proxy.Info(this.AxSession.AxaptaAdapter);
        //objInfoLog.add(Proxy.Exception.Warning, Convert.ToString(this.FormMode));
        switch (this.FormMode)
        {
            case ApplicationProxy.EPFormAction.EditMode:

                this.AXForm.DefaultMode = DetailsViewMode.Edit;
                this.AXForm.AutoGenerateEditButton = true;
                this.AXForm.AutoGenerateInsertButton = false;
             
                break;

            case ApplicationProxy.EPFormAction.CreateMode:
                this.AXForm.DefaultMode = DetailsViewMode.Insert;
                this.AXForm.AutoGenerateEditButton = false;
                //this.AXForm.AutoGenerateInsertButton = true;
                this.AxActionPaneControlTop.Visible = false;
                this.AxActionPaneControlEdit.Visible = true;
               
                break;

            default:
                this.AXForm.DefaultMode = DetailsViewMode.ReadOnly;
                this.AXForm.AutoGenerateEditButton = false;
                this.AXForm.AutoGenerateInsertButton = false;
                this.AxActionPaneControlTop.Visible = true;
                this.AxActionPaneControlEdit.Visible = false;
                break;
        }
    }
 
    void AxActionPaneControlTop_ActionMenuItemClicking(object sender, ActionMenuItemClickingEventArgs e)
    {
        e.RunMenuItem = false;
    }

    void AxActionPaneControl_ActionMenuItemClicked(object sender, ActionMenuItemEventArgs e)
    {

        switch (e.MenuItem.MenuItemAOTName.ToLower())
        {
            case MENU_ITEM_SaveAndClose:
                this.AXForm.InsertItem(true);
                DialogHelper.Close(CloseDialogBehavior.RefreshDataSource);
                break;
            case MENU_ITEM_Close:
                this.AXForm.DoCancel();
                DialogHelper.Close(CloseDialogBehavior.CloseOnly);
                break;
        }
    }

    void AxActionPaneControlTop_SetMenuItemProperties(object sender, SetMenuItemPropertiesEventArgs e)
    {
        string menuItemName = e.MenuItem.MenuItemAOTName.ToLower(System.Globalization.CultureInfo.InvariantCulture);

        switch (menuItemName)
        {
            case MENU_ITEM_Close:
                // Close should not trigger validation
                ((AxActionMenuItem)e.MenuItem).CausesValidation = false;
                break;
            //case MENUITEMNAME_SaveAndClose:
        }
    }
     protected override void OnInit(EventArgs e)
    {
        this.SetupMode();
        base.OnInit(e);
    }
}