Wednesday 28 January 2015

Create Transport order in ax 2012 R3 EP

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TransforOrder.ascx.cs" Inherits="TransforOrder" %>
<%@ Register Assembly="Microsoft.Dynamics.Framework.Portal, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="Microsoft.Dynamics.Framework.Portal.UI.WebControls" TagPrefix="dynamics" %>

<dynamics:AxDataSource ID="TransOrder" runat="server"
    DataSetName="EPSalesTableEdit" ProviderView="SalesTable"  >
</dynamics:AxDataSource>

 <dynamics:AxMultiSection ID="AxMultiSection1" runat="server">
     <dynamics:AxSection ID="AxSection1" runat="server">
         <dynamics:AxMultiColumn ID="AxMultiColumn1" runat="server">
             <dynamics:AxColumn ID="AxColumn1" runat="server">
                 <table style="width: 401px">
                 <tr>
                <td style="padding-left:19px;" align="left" class="style5">              
                    <asp:Label ID="lblSalesId" runat="server" AssociatedControlID="tbSalesId"
                        Text="Sales Id   " style="font-weight: 700"></asp:Label>
                </td>
                <td align="right">
                    <asp:TextBox class="AxInputField" ID="tbSalesId" Width="100%"
                        ToolTip="Enter the sales id" runat="server" ReadOnly="False"
                        Enabled="True" style="margin-left: 0px"></asp:TextBox>
                </td>
                <td>
                    <dynamics:AxLookup ID="AxLookup1" runat="server" AutoPostBack="true"
                    TargetControlId="tbSalesId"
                    OnLookup="DropDownSalesId_Lookup" TabIndex="1"
                    onokclicked="DropDownSalesId_OkClicked">
                    </dynamics:AxLookup>
                </td>
            </tr>             <tr>
                <td style="padding-left:19px;" align="left" class="style1">              
                    <asp:Label ID="lblModeOfTransport" runat="server" AssociatedControlID="tbModeOfTransport"
                        Text="Mode of transport   " style="font-weight: 700"></asp:Label>
                </td>
                <td align="right">
                    <asp:TextBox class="AxInputField" ID="tbModeOfTransport" Width="100%"
                        ToolTip="Enter the mode of transport" runat="server" ReadOnly="False"
                        Enabled="True" style="margin-left: 0px"></asp:TextBox>
                </td>
                <td>
                    <dynamics:AxLookup ID="DropDownModeOfTransport" runat="server" AutoPostBack="true"
                    TargetControlId="tbModeOfTransport"
                    OnLookup="DropDownModeOfTransport_Lookup" TabIndex="1"
                    onokclicked="DropDownModeOfTransport_OkClicked">
                    </dynamics:AxLookup>
                </td>
            </tr>
             <tr>
                <td style="padding-left:19px;" align="left" class="style2">              
                    <asp:Label ID="lblTransportProvider" runat="server" AssociatedControlID="tbTransportProvider"
                        Text="Transport provider" style="font-weight: 700"></asp:Label>
                </td>
                <td align="right">
                    <asp:TextBox class="AxInputField" ID="tbTransportProvider" Width="100%"
                        ToolTip="Enter the transport provider" runat="server" ReadOnly="False"
                        Enabled="True" style="margin-left: 0px"></asp:TextBox>
                </td>
                <td>
                    <dynamics:AxLookup ID="DropDownTransportProvider" runat="server" AutoPostBack="true"
                    TargetControlId="tbTransportProvider"
                    OnLookup="DropDowntbTransportProvider_Lookup" TabIndex="1"
                    onokclicked="DropDowntbTransportProvider_OkClicked">
                    </dynamics:AxLookup>
                </td>
            </tr>

            <tr>
                <td style="padding-left:19px;" align="left" class="style3">              
                    <asp:Label ID="lblRoutecard" runat="server" AssociatedControlID="tbRoutecard"
                        Text="Route card" style="font-weight: 700"></asp:Label>
                </td>
                 <td align="right">
                    <asp:TextBox class="AxInputField" ID="tbRoutecard" Width="100%"
                        ToolTip="Enter the route card" runat="server" ReadOnly="False"
                        Enabled="True" style="margin-left: 0px"></asp:TextBox>
                </td>
                 <td>
                    <dynamics:AxLookup ID="DropDownRoutecard" runat="server" AutoPostBack="true"
                    TargetControlId="tbRoutecard"
                    OnLookup="DropDowntbRoutecard_Lookup" TabIndex="1"
                    onokclicked="DropDowntbRoutecard_OkClicked">
                    </dynamics:AxLookup>
                </td>
            </tr>
             <tr>
                <td style="padding-left:19px;" align="left" class="style4">              
                    <asp:Label ID="Label1" runat="server" AssociatedControlID="tbRatecard"
                        Text="Rate card" style="font-weight: 700"></asp:Label>
                </td>
                 <td align="right">
                    <asp:TextBox class="AxInputField" ID="tbRatecard" Width="100%"
                        ToolTip="Enter the rate card" runat="server" ReadOnly="False"
                        Enabled="True" style="margin-left: 0px"></asp:TextBox>
                </td>
                <td>
                    <dynamics:AxLookup ID="DropDownRatecard" runat="server" AutoPostBack="true"
                    TargetControlId="tbRatecard"
                    OnLookup="DropDowntbRatecard_Lookup" TabIndex="1"
                    onokclicked="DropDowntbRatecard_OkClicked">
                    </dynamics:AxLookup>
                </td>
            </tr>
 </table>
             </dynamics:AxColumn>
         </dynamics:AxMultiColumn>
     </dynamics:AxSection>
</dynamics:AxMultiSection>


<p>
<asp:Button ID="Button1" runat="server" Text="Create" onclick="Button1_Click"
        style="margin-left: 243px" Width="60px" />
<asp:Button ID="Button2" runat="server" Text="Cancel" onclick="Button2_Click"
        style="margin-left: 5px" Width="50px" />
</p>
<dynamics:AxForm runat="server" ID="formEPSalesTableEdit"
    DataKeyNames="RecId"
    DataMember="SalesTable_Current"
    DataSourceID="TransOrder" DefaultMode="Edit" UpdateOnPostBack="true"
    AutoGenerateEditButton="False" ShowButtonsInActionPane="false" >
</dynamics:AxForm>
___________________________________________________________________________  
#region using
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls.WebParts;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls;
using Microsoft.Dynamics.Framework.BusinessConnector.Session;
using Microsoft.Dynamics.AX.Framework.Services.Client;
using Microsoft.Dynamics.AX.Framework.Portal.Data;
using Proxy = Microsoft.Dynamics.Framework.BusinessConnector.Proxy;
using Microsoft.Dynamics.Framework.BusinessConnector.Adapter;
using Microsoft.Dynamics.Framework.Portal.UI;
using Microsoft.Dynamics.Framework.Portal.CommonControls;

#endregion


public partial class TransforOrder : System.Web.UI.UserControl
{
    DataSetViewRow row;
    AxUrlMenuItem menuItem;
    string recId;

    /// <summary>
    /// Web part private
    /// </summary>
    AxBaseWebPart _baseWebpart = null;
    #region Properties
    /// <summary>
    /// Webpart
    /// </summary>
    AxBaseWebPart BaseWebpart
    {
        get
        {
            //return the basewebpart if it is not null
            if (this._baseWebpart != null)
                return this._baseWebpart;
            //get the webpart if basewebpart is null
            this._baseWebpart = AxBaseWebPart.GetWebpart(this);
            return this._baseWebpart;
        }
    }
    /// <summary>
    /// Gets the current Web Part Session.
    /// </summary>
    ISession AxSession
    {
        get
        {
            return BaseWebpart.Session;
        }
    }
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Page.Title = "Release to transport";
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Proxy.Info objInfoLog = new Proxy.Info(this.AxSession.AxaptaAdapter);
        string test,local;

        //String SalesidName = (String)this.TransOrder.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("getSalesId");
        test = this.tbSalesId.Text + this.tbModeOfTransport.Text + this.tbTransportProvider.Text + this.tbRoutecard.Text + this.tbRatecard.Text;
        if (test != "")
        {
            local = this.tbSalesId.Text;
            if (local != "")
            {
                AxSession.AxaptaAdapter.CallStaticRecordMethod("SalesTable", "localvalue",
                                                          this.tbSalesId.Text,
                                                          this.tbModeOfTransport.Text,
                                                          this.tbTransportProvider.Text,
                                                          this.tbRoutecard.Text,
                                                          this.tbRatecard.Text);

                DialogHelper.Close();
            }
            else
            {
                objInfoLog.add(Proxy.Exception.Warning, "Please select the Sales order");
            }
        }
        else
        {
            objInfoLog.add(Proxy.Exception.Warning, "Please select the parameters");
        }

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        DialogHelper.Close();
    }

    protected void DropDownSalesId_OkClicked(object sender, AxLookupEventArgs e)
    {
        //this.loadProdGroupDrpDown();
    }
    protected void DropDownSalesId_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup nameLookup = e.LookupControl;
        //TxtWarehouseCode.Text = "";
        try
        {
            AxLookup lookup = (AxLookup)sender;
            // Create the lookup dataset - we will do a lookup in the DirPartyTable table
            using (Proxy.SysDataSetBuilder sysDataSetBuilder = Proxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, "Salestable")))
            {
                // Set the run time generated data set as the lookup data set
                nameLookup.LookupDataSet = new Microsoft.Dynamics.AX.Framework.Portal.Data.DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
            }
            // DataSet has to be init'ed before accessing the data sources
            nameLookup.LookupDataSet.Init();
            // Filter the lookup
            using (Proxy.Query query = nameLookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
            {
                using (Proxy.QueryBuildDataSource qbds = query.dataSourceNo(1))
                {
                    qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "SalesTable", "OrderTransported")).value = "0";
                    qbds.addOrderByField(TableDataFieldMetadata.FieldNum(this.AxSession, "SalesTable", "Salesid"));
                    qbds.orderMode = (int)OrderMode.GroupBy;
                }
            }
            // Specify the lookup fields used
            nameLookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, nameLookup.LookupDataSetViewMetadata.ViewFields["SalesId"]));
            // Specify the select field
            nameLookup.SelectField = "SalesId";
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;
            // This returns true if the exception can be handled here
            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
            {
                // The exception is system fatal - in this case we re-throw.                                  
                throw;
            }
        }
    }
    protected void DropDownModeOfTransport_OkClicked(object sender, AxLookupEventArgs e)
    {
        //this.loadProdGroupDrpDown();
    }
    protected void DropDownModeOfTransport_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup nameLookup = e.LookupControl;
        //TxtWarehouseCode.Text = "";
        try
        {
            AxLookup lookup = (AxLookup)sender;
            // Create the lookup dataset - we will do a lookup in the DirPartyTable table
            using (Proxy.SysDataSetBuilder sysDataSetBuilder = Proxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, "DIPL_ModeOfTrans")))
            {
                // Set the run time generated data set as the lookup data set
                nameLookup.LookupDataSet = new Microsoft.Dynamics.AX.Framework.Portal.Data.DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
            }
            // DataSet has to be init'ed before accessing the data sources
            nameLookup.LookupDataSet.Init();
            // Filter the lookup
            using (Proxy.Query query = nameLookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
            {
                using (Proxy.QueryBuildDataSource qbds = query.dataSourceNo(1))
                {
                   // qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "BPGroup")).value = this.tbBPGroup.Text;
                    qbds.addOrderByField(TableDataFieldMetadata.FieldNum(this.AxSession, "DIPL_ModeOfTrans", "ModeOfTransport"));
                    qbds.orderMode = (int)OrderMode.GroupBy;
                }
            }
            // Specify the lookup fields used
            nameLookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, nameLookup.LookupDataSetViewMetadata.ViewFields["ModeOfTransport"]));
            // Specify the select field
            nameLookup.SelectField = "ModeOfTransport";
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;
            // This returns true if the exception can be handled here
            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
            {
                // The exception is system fatal - in this case we re-throw.                                  
                throw;
            }
        }
    }
    protected void DropDowntbTransportProvider_OkClicked(object sender, AxLookupEventArgs e)
    {
        //this.loadProdGroupDrpDown();
    }
    protected void DropDowntbTransportProvider_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup nameLookup = e.LookupControl;
        //TxtWarehouseCode.Text = "";
        try
        {
            AxLookup lookup = (AxLookup)sender;
            // Create the lookup dataset - we will do a lookup in the DirPartyTable table
            using (Proxy.SysDataSetBuilder sysDataSetBuilder = Proxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, "DIPL_TransportProviderMaster")))
            {
                // Set the run time generated data set as the lookup data set
                nameLookup.LookupDataSet = new Microsoft.Dynamics.AX.Framework.Portal.Data.DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
            }
            // DataSet has to be init'ed before accessing the data sources
            nameLookup.LookupDataSet.Init();
            // Filter the lookup
            using (Proxy.Query query = nameLookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
            {
                using (Proxy.QueryBuildDataSource qbds = query.dataSourceNo(1))
                {
                    // qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "BPGroup")).value = this.tbBPGroup.Text;
                    qbds.addOrderByField(TableDataFieldMetadata.FieldNum(this.AxSession, "DIPL_TransportProviderMaster", "DIPL_TransportProvider"));
                    qbds.orderMode = (int)OrderMode.GroupBy;
                }
            }
            // Specify the lookup fields used
            nameLookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, nameLookup.LookupDataSetViewMetadata.ViewFields["DIPL_TransportProvider"]));
            // Specify the select field
            nameLookup.SelectField = "DIPL_TransportProvider";
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;
            // This returns true if the exception can be handled here
            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
            {
                // The exception is system fatal - in this case we re-throw.                                  
                throw;
            }
        }
    }
    protected void DropDowntbRoutecard_OkClicked(object sender, AxLookupEventArgs e)
    {
        //this.loadProdGroupDrpDown();
    }
    protected void DropDowntbRoutecard_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup nameLookup = e.LookupControl;
        //TxtWarehouseCode.Text = "";
        try
        {
            AxLookup lookup = (AxLookup)sender;
            // Create the lookup dataset - we will do a lookup in the DirPartyTable table
            using (Proxy.SysDataSetBuilder sysDataSetBuilder = Proxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, "DIPL_RoutecardMaster")))
            {
                // Set the run time generated data set as the lookup data set
                nameLookup.LookupDataSet = new Microsoft.Dynamics.AX.Framework.Portal.Data.DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
            }
            // DataSet has to be init'ed before accessing the data sources
            nameLookup.LookupDataSet.Init();
            // Filter the lookup
            using (Proxy.Query query = nameLookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
            {
                using (Proxy.QueryBuildDataSource qbds = query.dataSourceNo(1))
                {
                    // qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "BPGroup")).value = this.tbBPGroup.Text;
                    qbds.addOrderByField(TableDataFieldMetadata.FieldNum(this.AxSession, "DIPL_RoutecardMaster", "DIPL_Routecard"));
                    qbds.orderMode = (int)OrderMode.GroupBy;
                }
            }
            // Specify the lookup fields used
            nameLookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, nameLookup.LookupDataSetViewMetadata.ViewFields["DIPL_Routecard"]));
            // Specify the select field
            nameLookup.SelectField = "DIPL_Routecard";
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;
            // This returns true if the exception can be handled here
            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
            {
                // The exception is system fatal - in this case we re-throw.                                  
                throw;
            }
        }
    }
    protected void DropDowntbRatecard_OkClicked(object sender, AxLookupEventArgs e)
    {
        //this.loadProdGroupDrpDown();
    }
    protected void DropDowntbRatecard_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup nameLookup = e.LookupControl;
        //TxtWarehouseCode.Text = "";
        try
        {
            AxLookup lookup = (AxLookup)sender;
            // Create the lookup dataset - we will do a lookup in the DirPartyTable table
            using (Proxy.SysDataSetBuilder sysDataSetBuilder = Proxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, "DIPL_RatecardMaster")))
            {
                // Set the run time generated data set as the lookup data set
                nameLookup.LookupDataSet = new Microsoft.Dynamics.AX.Framework.Portal.Data.DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
            }
            // DataSet has to be init'ed before accessing the data sources
            nameLookup.LookupDataSet.Init();
            // Filter the lookup
            using (Proxy.Query query = nameLookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
            {
                using (Proxy.QueryBuildDataSource qbds = query.dataSourceNo(1))
                {
                    // qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "BPGroup")).value = this.tbBPGroup.Text;
                    qbds.addOrderByField(TableDataFieldMetadata.FieldNum(this.AxSession, "DIPL_RatecardMaster", "DIPL_Ratecard"));
                    qbds.orderMode = (int)OrderMode.GroupBy;
                }
            }
            // Specify the lookup fields used
            nameLookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, nameLookup.LookupDataSetViewMetadata.ViewFields["DIPL_Ratecard"]));
            // Specify the select field
            nameLookup.SelectField = "DIPL_Ratecard";
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;
            // This returns true if the exception can be handled here
            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
            {
                // The exception is system fatal - in this case we re-throw.                                  
                throw;
            }
        }
    }
 
}

This code is used to add Multi select lookup in EP from AX table 2012 R3

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebControl1.ascx.cs" Inherits="WebControl1" %>
<table>
    <tr>
        <td class="dynJoiningPart"><asp:Label ID="Label1" runat="server" Text="Publish to customer group"></asp:Label></td> 

        <td><asp:TextBox ID="SegmentGrpTxt" runat="server" Visible="true" Width="500"></asp:TextBox></td>

        <td class="dynJoiningPart"><dynamics:AxLookup ID="SegmentsGroupID" runat="server" TargetControlId="SegmentGrpTxt"

        ExtendedDataType="smmSegmentId" LookupType="EDT" AllowMarking="true"

        OnLookup="SegmentsGroupID_Lookup" OnOkClicked="SegmentsGroupID_OkClicked"> 

        </dynamics:AxLookup></td>
    </tr>
</table>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls.WebParts;
using Microsoft.Dynamics.AX.Framework.Services.Client;
using Microsoft.Dynamics.Framework.BusinessConnector.Session;
using Microsoft.Dynamics.AX.Framework.Reporting.Shared;
using Microsoft.Dynamics.Framework.Portal.UI;
using BCProxy = Microsoft.Dynamics.Framework.BusinessConnector.Proxy;
using System.Data;
using System.Collections;
using Microsoft.Dynamics.Framework.BusinessConnector.Adapter;
using Microsoft.Dynamics.AX.Framework.Portal.Data;


public partial class WebControl1 : System.Web.UI.UserControl

{
    private DateTime Today
    {
        get
        {
            return AxDateTimeHelper.GetUserNow(this.AxSession).Date;
        }
    }
    private ISession AxSession
    {
        get
        {
            AxBaseWebPart webpart = AxBaseWebPart.GetWebpart(this);
            return webpart == null ? null : webpart.Session;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void SegmentsGroupID_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup nameLookup = e.LookupControl;
        //TxtWarehouseCode.Text = "";
        try
        {
            AxLookup lookup = (AxLookup)sender;
            // Create the lookup dataset - we will do a lookup in the DirPartyTable table
            using (BCProxy.SysDataSetBuilder sysDataSetBuilder = BCProxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, "EcoresCategory")))
            {
                // Set the run time generated data set as the lookup data set
                nameLookup.LookupDataSet = new Microsoft.Dynamics.AX.Framework.Portal.Data.DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
            }
            // DataSet has to be init'ed before accessing the data sources
            nameLookup.LookupDataSet.Init();
            // Filter the lookup 
            using (BCProxy.Query query = nameLookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
            {
                using (BCProxy.QueryBuildDataSource qbds = query.dataSourceNo(1))
                {
                  //  qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "EcoResCategory", "Level")).value = "2";
                   // qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "EcoResCategory", "ShowOnEP")).value = "Yes";
                    qbds.addOrderByField(TableDataFieldMetadata.FieldNum(this.AxSession, "EcoResCategory", "Name"));
                    qbds.orderMode = (int)OrderMode.GroupBy;
                }
            }
            // Specify the lookup fields used
            nameLookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, nameLookup.LookupDataSetViewMetadata.ViewFields["Name"]));
            // Specify the select field
            nameLookup.SelectField = "Name";
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;
            // This returns true if the exception can be handled here
            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
            {
                // The exception is system fatal - in this case we re-throw.                                    
                throw;
            }
        }
    }
    protected void SegmentsGroupID_OkClicked(object sender, AxLookupEventArgs e)
    {

        string retval = "";


        // Look at each value returned from the multi-select lookup


        foreach (DataSetViewRow row in e.LookupControl.LookupDataSetView.GetMarkedRowsSet())

        {

            // Retrieve the Work Order Number from the current marked row


            retval = retval + row.GetFieldValue("Name").ToString() + " ; ";



        }

        // Display the results in a text box



        SegmentGrpTxt.Text = retval;


    }



}






_________________________________________________________________________________
This code is used to add Multi select lookup in EP from AX table.



<td class="dynJoiningPart"><asp:Label ID="Label1" runat="server" Text="Publish to customer group"></asp:Label></td> 

 <td><asp:TextBox ID="SegmentGrpTxt" runat="server" Visible="true" Width="500"></asp:TextBox></td>

 <td class="dynJoiningPart"><dynamics:AxLookup ID="SegmentsGroupID" runat="server" TargetControlId="SegmentGrpTxt"

 ExtendedDataType="smmSegmentId" LookupType="EDT" AllowMarking="true"

 OnLookup="SegmentsGroupID_Lookup" OnOkClicked="SegmentsGroupID_OkClicked"> 

 </dynamics:AxLookup></td>

-----------------------------------------------------------------------------------------------------------------

 protected void SegmentsGroupID_Lookup(object sender, AxLookupEventArgs e)

{


AxLookup lookup = (AxLookup)sender;


SegmentGrpTxt.Text = "";


// Create the lookup data set. The smmBusRelSegmentGroup table will be used.


Proxy.SysDataSetBuilder sysDataSetBuilder;


sysDataSetBuilder = Proxy.SysDataSetBuilder.constructLookupDataSet(AxSession.AxaptaAdapter,TableMetadata.TableNum(AxSession, "smmBusRelSegmentGroup"));


// Set the generated data set as the lookup data set.


lookup.LookupDataSet = new DataSet(AxSession, sysDataSetBuilder.toDataSet());


// Specify the fields for the lookup.


lookup.Fields.Add(AxBoundFieldFactory.Create(AxSession, lookup.LookupDataSetViewMetadata.ViewFields["SegmentId"]));


lookup.Fields.Add(AxBoundFieldFactory.Create(AxSession, lookup.LookupDataSetViewMetadata.ViewFields["Description"]));


// Specify the select field for the lookup.


lookup.SelectField = "SegmentId";



}



protected void SegmentsGroupID_OkClicked(object sender, AxLookupEventArgs e)


{


string retval = "";


// Look at each value returned from the multi-select lookup


foreach (DataSetViewRow row in e.LookupControl.LookupDataSetView.GetMarkedRowsSet())


{


// Retrieve the Work Order Number from the current marked row


retval = retval + row.GetFieldValue("SegmentId").ToString() + " - ";



}



// Display the results in a text box


SegmentGrpTxt.Text = retval;


}

-----------------------------------------------------------------------------------------------------------------------
protected int FillCustGroupList()
{
string fieldvalue;
int nrec = 0;
int rowcount = 0;


        
// Get the data set
DataSet ds = this.AvaSmmBusRelSegmentGroupDS.GetDataSet();
AxDataSourceView SegGroupDS = AvaSmmBusRelSegmentGroupDS.GetDataSourceView("smmBusRelSegmentGroup");
        
// Add the views for the data set to the list.
foreach (DataSetView dsv in ds.DataSetViews)
{
            
rowcount = dsv.GetTotalNumberOfRows();
 
            
for (int i = 1; i <= rowcount; i++)
{
nrec++;
                
fieldvalue = dsv.GetCurrent().GetFieldValue("SegmentId").ToString();
                
}
}
return nrec;
}

Monday 26 January 2015

SSRS Report in ax 2012 UI builder and controller

1./// <summary>
///    The <c>StockOnHandController</c> class is a controller class for the <c>StockOnHandController report</c>
///    report.
/// </summary>
class StockOnHandController extends SrsReportRunController
{
    StockOnHandContract                     StockOnHandContract;
    Inventtable                                 _Inventtable;
    #define.ReportName('StockOnHand.design')
}
/// <summary>
///    Override this method to change the report contract before you run the report.
/// </summary>
public void preRunModifyContract()
{
    SrsReportRdlDataContract    rdlContractInfo;
    rdlContractInfo = this.parmReportContract().parmRdlContract();
    StockOnHandContract = this.parmReportContract().parmRdpContract() as StockOnHandContract;
    _Inventtable = this.parmArgs().record();

    StockOnHandContract.parmItemid(_Inventtable.ItemId);
  

}
protected boolean validate()
{
    boolean ret;
    ret = super();
    if (! args.record())
    {
        ret = checkFailed("Windows must be called with active record buffer");
    }
    return ret;
}
public client static void main(Args _args)
{
    StockOnHandController controller = new StockOnHandController();
    controller.parmReportName(#ReportName);
    controller.parmLoadFromSysLastValue(false);
    controller.parmArgs(_args);
    controller.parmShowDialog(false);
    controller.startOperation();
}

2. Create the One out put type menuitem with this class
3. Go To your form and Create one Menuitembutton - select the properties like datasourceName,MenuitemType,MenuItemName

-----------------------------------------
Contract class:-
[
    DataContractAttribute,
    SysOperationContractProcessingAttribute(classStr(StockonHandUIBuilder))
]
class StockonHandContract implements SysOperationValidatable
{
    EcoResCategoryName  bpGroup;
    EcoResCategoryName  prodGroup;
    EcoResCategoryName  ProductCategory;
    Itemid              Itemid;
    InventLocationId    InventLocationId;
}
[
    DataMemberAttribute('BPGroup'),
    SysOperationLabelAttribute('BP Group')
]
public EcoResCategoryName parmBPGroup(EcoResCategoryName _bpGroup = bpGroup)
{
    bpGroup = _bpGroup;
    return bpGroup;
}
[
DataMemberAttribute('Itemid'),
SysOperationLabelAttribute('Item Number')
]
public Itemid parmItemid(Itemid _Itemid = Itemid)
{
    Itemid = _Itemid;
    return Itemid;
}
[
DataMemberAttribute('ProdGroup'),
SysOperationLabelAttribute('Product Group')
]
public EcoResCategoryName parmProdGroup(EcoResCategoryName _prodGroup = prodGroup)
{
    prodGroup = _prodGroup;
    return prodGroup;
}
[
DataMemberAttribute('EcoResCategoryName'),
SysOperationLabelAttribute('Prod Category')
]
public EcoResCategoryName parmProductCategory(EcoResCategoryName _ProductCategory = ProductCategory)
{
    ProductCategory = _ProductCategory;
    return ProductCategory;
}
[
DataMemberAttribute('InventLocationId'),
SysOperationLabelAttribute('Warehouse')
]
public InventLocationId parmWarehouse(InventLocationId _InventLocationId = InventLocationId)
{
    InventLocationId = _InventLocationId;
    return InventLocationId;
}
/// <summary>
///    Determines whether the parameters are valid.
/// </summary>
/// <returns>
///    true when the parameters are valid; otherwise, false.
/// </returns>
public boolean validate()
{
    boolean isValid = true;
    if (prodGroup && !bpGroup)
    {
        isValid = checkFailed(strFmt("BP Group to be filled in"));
    }
    if (ProductCategory && ! ProdGroup)
    {
        isValid = checkFailed(strFmt("Product Group to be filled in"));
    }

    return isValid;
}
public static StockonHandContract construct()
{
    return new StockonHandContract();
}
-----------------------------------DP Class
[
    SRSReportQueryAttribute(querystr(ProductDisplayView)),
    SRSReportParameterAttribute(classStr(StockonHandContract))
]
public class StockOnHandDP extends SRSReportDataProviderBase
{
    StockOnHandTMP StockonHandTMP;
    EcoResCategoryName  bpGrouploc,bpGrouplocvalue;
    EcoResCategoryName  prodGrouploc,prodGrouplocvalue;
    EcoResCategoryName  ProductCategoryloc,ProductCategorylocvalue;
    Itemid              Itemidloc;
    InventLocationId    InventLocationIdloc;
}
[SRSReportDataSetAttribute('StockOnHandTMP')]
public StockOnHandTMP getStockOnHandTMP()
{
    select * from StockOnHandTMP;
    return StockonHandTMP;
}
public void processreport()
{
    Query                   query;
    QueryBuildDataSource    qbds;
    QueryBuildRange         qbr,qbr1,qbr2,qbr3,qbr4,qbr5;
    QueryRun                qr;
    StockonHandContract datacontract;
    InventTable             inventtable;
    ProductDisplayView  _ProductDisplayView;
    InventLocation          inventlocation;
    InventDim               InventDim;
    InventTableModule       InventTableModule;
    InventOnhand    _inventonhand;
    InventDimParm   _inventDimParm;
    InventQty       _inventQty;
    query                  = new query();
    datacontract           = this.parmDataContract();
    bpGrouploc         = datacontract.parmBPGroup();
    prodGrouploc       = datacontract.parmProdGroup();
    ProductCategoryloc = datacontract.parmProductCategory();
    Itemidloc          = datacontract.parmItemid();
    InventLocationIdloc= datacontract.parmWarehouse();
    if(prodGrouploc)
    {
        prodGrouplocvalue = prodGrouploc +"_"+bpGrouploc;
    }
    if(ProductCategoryloc)
    {
        ProductCategorylocvalue =ProductCategoryloc+"_"+prodGrouploc +"_"+bpGrouploc;
    }

    qbds = query.addDataSource(tablenum(ProductDisplayView));
    qbds.addSortField(fieldNum(ProductDisplayView,BPGroup),SortOrder::Ascending);
    if(bpGrouploc)
    {
         qbr = qbds.findRange(fieldnum(ProductDisplayView, BPGroup));
        if (!qbr)
        {
            qbr = qbds.addRange(fieldnum(ProductDisplayView, BPGroup));
        }
        if(!qbr.value())
            qbr.value(queryValue(bpGrouploc));
    }
    if(prodGrouploc)
    {
         qbr1 = qbds.findRange(fieldnum(ProductDisplayView, ProductGroup));
        if (!qbr1)
        {
            qbr1 = qbds.addRange(fieldnum(ProductDisplayView, ProductGroup));
        }
        if(!qbr1.value())
            qbr1.value(queryValue(prodGrouplocvalue));
    }
    if(ProductCategoryloc)
    {
         qbr2 = qbds.findRange(fieldnum(ProductDisplayView, ProductCategory));
        if (!qbr2)
        {
            qbr2 = qbds.addRange(fieldnum(ProductDisplayView, ProductCategory));
        }
        if(!qbr2.value())
            qbr2.value(queryValue(ProductCategorylocvalue));
    }
    if(Itemidloc)
    {
         qbr3 = qbds.findRange(fieldnum(ProductDisplayView, ItemId));
        if (!qbr3)
        {
            qbr3 = qbds.addRange(fieldnum(ProductDisplayView, ItemId));
        }
        if(!qbr3.value())
            qbr3.value(queryValue(Itemidloc));
    }
    qr = new QueryRun(query);
    while(qr.next())
    {
        _ProductDisplayView  = qr.get(tableNum(ProductDisplayView));
        select inventtable where inventtable.itemid  == _ProductDisplayView.ItemId;
        StockonHandTMP.BPGroup             = inventtable.BPGroupName();
        StockonHandTMP.ProdGroup           = inventtable.productGroupName();
        StockonHandTMP.ProdCategory        = inventtable.productCategoryName();
        StockonHandTMP.ItemCode            = _ProductDisplayView.ItemId;
        StockonHandTMP.ItemName            = _ProductDisplayView.Name;
        select InventTableModule where InventTableModule.ItemId == _ProductDisplayView.ItemId;
        StockonHandTMP.UOM = InventTableModule.UnitId;
        while select inventlocation where inventlocation.InventSiteId     == SysUserInfo::find(curUserId()).InventSiteId
                            && (((InventLocationIdloc)   &&(inventlocation.InventLocationId  == InventLocationIdloc))||(!InventLocationIdloc))
        if(inventlocation.RecId)
        {
            StockonHandTMP.InventLocationId    = inventlocation.InventLocationId;
            StockonHandTMP.InventLocationName  = inventlocation.Name;
            StockonHandTMP.InventSiteId        = InventLocation::find(StockonHandTMP.InventLocationId).InventSiteId;
            StockonHandTMP.InventSiteName      = InventSite::find(InventLocation::find(StockonHandTMP.InventLocationId).InventSiteId).Name;
            select InventDim where InventDim.InventLocationId == inventlocation.InventLocationId;
            _inventDimParm.initFromInventDim(InventDim);
            _inventonhand = InventOnhand::newParameters(_ProductDisplayView.ItemId ,InventDim,_inventDimParm);
            _inventQty =_inventonhand.availPhysical();
            StockonHandTMP.AvailPhysical       = _inventQty;//InventSum::find(_ProductDisplayView.ItemId,InventDim.inventDimId).AvailPhysical;
            if(StockonHandTMP.AvailPhysical)
            {
                StockonHandTMP.insert();
            }
        }
    }
}
------------------UI Builder:
class StockonHandUIBuilder extends SrsReportDataContractUIBuilder
{
    DialogField               dialogBPGroup,dialogProductGroup,dialogProductCategory,dialogItemid,dialogLocation;
    StockonHandContract   Contract;
}
public void build()
{
    contract               = this.dataContractObject();
    dialogBPGroup          = this.addDialogField(methodStr(StockonHandContract, parmBPGroup),contract);
    dialogProductGroup     = this.addDialogField(methodStr(StockonHandContract, parmProdGroup),contract);
    dialogProductCategory  = this.addDialogField(methodStr(StockonHandContract, parmProductCategory),contract);
    dialogItemid           = this.addDialogField(methodStr(StockonHandContract, parmItemid),contract);
    dialogLocation         = this.addDialogField(methodStr(StockonHandContract, parmWarehouse),contract);
}
public void getFromDialog()
{
    contract = this.dataContractObject();
    super();
}
public void initializeFields()
{
    contract = this.dataContractObject();
}
public void lookupBPGroup(FormStringControl _control)
{
    Query           query = new Query();
    SysTableLookup  sysTableLookup;
    QueryBuildDataSource qbds;
    QueryBuildDataSource qbdsSet;
    // Create an instance of SysTableLookup using the specified control.
    sysTableLookup = SysTableLookup::newParameters(tableNum(EcoResCategory), _control);
    // Add Name field to be shown in the lookup form.
    sysTableLookup.addLookupfield(fieldNum(EcoResCategory, Name));
    qbds = query.addDataSource(tableNum(EcoResCategory));
    qbds.addRange(fieldNum(EcoResCategory, Level)).value(queryValue(2));
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
public void lookupItemid(FormStringControl _control)
{
    Query                       query = new Query();
    SysTableLookup              sysTableLookup;
    QueryBuildDataSource        qbds;
    QueryBuildDataSource        qbdsSet;
    EcoResCategory              bpGroupNode,ProdGroupNode,ProdcategoryNode,ecoresCategory;
    EcoResCategoryHierarchyId   defaultCategory;
    name                       _productvalue,productcat;
    recid                       ecoresCategoryrecid;
    ;
    defaultCategory = FTPParameters::find().DefaultCategory;
    bpGroupNode     = EcoResCategory::findByName(dialogBPGroup.value(), defaultCategory);
    if(dialogProductGroup.value())
    {
         while select  ProdGroupNode where ProdGroupNode.ParentCategory == bpGroupNode.RecId
        {
            if(dialogProductGroup.value() == ProdGroupNode.prodGroupDisplayName())
            {
               _Productvalue        = ProdGroupNode.Name;
                ecoresCategoryrecid = ProdGroupNode.RecId;
            }
        }
    }
    if(dialogProductCategory.value())
    {
         while select  ProdcategoryNode where ProdcategoryNode.ParentCategory == ecoresCategoryrecid
        {
            if(dialogProductCategory.value() == ProdcategoryNode.prodCategorydisplayName())
            {
               productcat = ProdcategoryNode.Name;
            }
        }
    }
    sysTableLookup  = SysTableLookup::newParameters(tableNum(ProductDisplayView), _control);
    sysTableLookup.addLookupfield(fieldNum(ProductDisplayView,ItemId));
    sysTableLookup.addLookupfield(fieldNum(ProductDisplayView,name));
  //  sysTableLookup.addLookupMethod(tableMethodStr(ProductDisplayView, itemName), true);
    qbds = query.addDataSource(tableNum(ProductDisplayView));
    if(dialogBPGroup.value())
    {
        qbds.addRange(fieldNum(ProductDisplayView, BPGroup)).value(queryValue(bpGroupNode.Name));
    }
    if(dialogProductGroup.value())
    {
        qbds.addRange(fieldNum(ProductDisplayView, ProductGroup)).value(queryValue(_Productvalue));
    }
    if(dialogProductCategory.value())
    {
        qbds.addRange(fieldNum(ProductDisplayView, ProductCategory)).value(queryValue(productcat));
    }
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
public void lookupLocation(FormStringControl _control)
{
    Query                       query = new Query();
    SysTableLookup              sysTableLookup;
    QueryBuildDataSource        qbds;
    QueryBuildDataSource        qbdsSet;
    EcoResCategory              bpGroupNode,ProdGroupNode;
    EcoResCategoryHierarchyId   defaultCategory;
    ;
    sysTableLookup  = SysTableLookup::newParameters(tableNum(InventLocation), _control);
    sysTableLookup.addLookupfield(fieldNum(InventLocation,InventLocationId));
    sysTableLookup.addLookupfield(fieldNum(InventLocation,Name));
    qbds = query.addDataSource(tableNum(InventLocation));
    qbds.addRange(fieldNum(InventLocation, InventSiteId)).value(queryValue(SysUserInfo::find(curUserId()).InventSiteId));
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
public void lookupProdGroup(FormStringControl _control)
{
    Query                       query = new Query();
    SysTableLookup              sysTableLookup;
    QueryBuildDataSource        qbds;
    QueryBuildDataSource        qbdsSet;
    EcoResCategory              bpGroupNode;
    EcoResCategoryHierarchyId   defaultCategory;
    defaultCategory = FTPParameters::find().DefaultCategory;
    bpGroupNode = EcoResCategory::findByName(dialogBPGroup.value(), defaultCategory);
    // Create an instance of SysTableLookup using the specified control.
    sysTableLookup = SysTableLookup::newParameters(tableNum(EcoResCategory), _control);
    // Add Name field to be shown in the lookup form.
    sysTableLookup.addLookupMethod(tableMethodStr(EcoResCategory, prodGroupDisplayName), true);
    qbds = query.addDataSource(tableNum(EcoResCategory));
    qbds.addRange(fieldNum(EcoResCategory, Level)).value(queryValue(3));
    if(dialogBPGroup.value())
    {
        qbds.addRange(fieldNum(EcoResCategory, ParentCategory)).value(queryValue(bpGroupNode.RecId));
    }
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
public void lookupProductCategory(FormStringControl _control)
{
    Query                       query = new Query();
    SysTableLookup              sysTableLookup;
    QueryBuildDataSource        qbds;
    QueryBuildDataSource        qbdsSet;
    EcoResCategory              bpGroupNode,ProdGroupNode;
    EcoResCategoryHierarchyId   defaultCategory;
    RecId                       _Productvalue;
    ;
    defaultCategory = FTPParameters::find().DefaultCategory;
    bpGroupNode = EcoResCategory::findByName(dialogBPGroup.value(), defaultCategory);

    while select  ProdGroupNode where ProdGroupNode.ParentCategory == bpGroupNode.RecId
    {
        if(dialogProductGroup.value() == ProdGroupNode.prodGroupDisplayName())
        {
           _Productvalue = ProdGroupNode.RecId;
        }
    }
    sysTableLookup  = SysTableLookup::newParameters(tableNum(EcoResCategory), _control);
    sysTableLookup.addLookupMethod(tableMethodStr(EcoResCategory, prodCategorydisplayName), true);
    qbds = query.addDataSource(tableNum(EcoResCategory));
    qbds.addRange(fieldNum(EcoResCategory, Level)).value(queryValue(4));
    if(dialogProductGroup.value())
    {
        qbds.addRange(fieldNum(EcoResCategory, ParentCategory)).value(queryValue(_Productvalue));
    }
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
/// <summary>
/// Overrides the default values in order to handle events on dialogs.
/// </summary>
public void postRun()
{
    super();
    dialogBPGroup.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(StockonHandUIBuilder, lookupBPGroup),this);
    dialogProductGroup.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(StockonHandUIBuilder, lookupProdGroup),this);
    dialogProductCategory.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(StockonHandUIBuilder, lookupProductCategory),this);
    dialogItemid.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(StockonHandUIBuilder, lookupItemid),this);
    dialogLocation.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(StockonHandUIBuilder, lookupLocation),this);
    //dialogShowCritical.value(NoYes::Yes);
}