Wednesday, 28 January 2015

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

No comments:

Post a Comment