Quantcast
Channel: Microsoft Dynamics AX
Viewing all articles
Browse latest Browse all 125409

Blog Post: Ax 2012 EP Lookup as Tree view – Simple example

$
0
0

This is an example gives the basic idea for displaying the lookup as a tree view control in EP and usage of AxPopup controls in EP.

How to Develop

1. On CustTable implement the following method.

public static Array getAllRecords()
{
CustTable custTable;
DirPartyTable DirPartyTable;
int i=1;
Array customerList = new Array(Types::String);
while select AccountNum from custTable join name from DirPartyTable
where custTable.Party == DirPartyTable.RecId
{
customerList.value(i, custTable.AccountNum);
customerList.value(i+1, DirPartyTable.name);
i+=2;
}
return customerList;
}

2.  Deploy the proxies from Tools – Web development – Proxies.

3. Create the  following web part GDCustomerFilter

<%@ Control Language=”C#” AutoEventWireup=”true” CodeFile=”GDCustomerFilter.ascx.cs” Inherits=”GDCustomerFilter” %>

<table>
<tr>
<td>
<asp:TextBox runat=”server” ID=”TextBoxFilterCustAccount”></asp:TextBox>
</td>
<td>

<dynamics:AxLookup ID=”AxLookup3″ runat=”server” OnLookup=”Customer_LookUp”
TargetControlId=”TextBoxFilterCustAccount” PredefinedButtons=”None” ShowFilter=”False” BorderStyle=”None”>
</dynamics:AxLookup>
<asp:Label ID=”ErrorMesg” runat=”server” Visible=”False” Font-Bold=”True”
ForeColor=”Red”></asp:Label>
</td>
</tr>
</table>

<dynamics:AxPopupParentControl ID=”TreeLookupParent” runat=”server” PopupHeight =”400″ PopupWidth=”450″ Align=”Center”>
<dynamics:AxPopupField name=”selectedName” />

</dynamics:AxPopupParentControl>
Code behind

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.Framework.Portal.UI;
using Microsoft.Dynamics.AX.Framework.Portal.Data;
using Proxy = Microsoft.Dynamics.Framework.BusinessConnector.Proxy;
using Microsoft.Dynamics.AX.Framework.Services.Client;
using Microsoft.Dynamics.Framework.BusinessConnector.Session;
using Microsoft.Dynamics.Framework.BusinessConnector.Adapter;

public partial class GDCustomerFilter : System.Web.UI.UserControl
{
private ISession AxSession
{
get
{
AxBaseWebPart webpart = AxBaseWebPart.GetWebpart(this);
return webpart.Session;
}
}

private AxBaseWebPart WebPart
{
get { return AxBaseWebPart.GetWebpart(this); }
}

protected void Customer_LookUp(object sender, AxLookupEventArgs e)
{

AxLookup lookup = e.LookupControl;
int custTableId = TableMetadata.TableNum(this.AxSession, “CustTable”);

//Create the lookup dataset – we will do a lookup in the CustTable table – To make error free. Use following code for default lookup behaviour.
using (Proxy.SysDataSetBuilder sysDataSetBuilder = Proxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, “CustTable”)))
{

// Set the run time generated data set as the lookup data set
lookup.LookupDataSet = new DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
}
lookup.LookupDataSet.Init();
// Specify the lookup fields used
lookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, lookup.LookupDataSetViewMetadata.ViewFields["AccountNum"]));

// Specify the select field
lookup.SelectField = “AccountNum”;

//Here stopped default lookup behaviuor
lookup.DefaultLookupGrid.Visible = false;

//Calling our tree control page as a Popup
AxUrlMenuItem menuItem = new AxUrlMenuItem(“GDEPCustTreeView”);
string custName = TreeLookupParent.GetFieldValue(“selectedName”);

if (string.IsNullOrEmpty(custName))
{
TreeLookupParent.OpenPopup(menuItem);
}
this.TextBoxFilterCustAccount.Text = custName;
TreeLookupParent.SetFieldValue(“selectedName”, “”);

}

4. Create a new page in share point under the following module

Sales/Enterprise%20Portal/GDEPCustomerFilter.aspx – and host the above web part.

5. Create another web part with the name – GDEPCustTreeView

Other web part for Tree Control

<%@ Control Language=”C#” AutoEventWireup=”true” CodeFile=”GDEPCustTreeView.ascx.cs” Inherits=”GDEPCustTreeView” %>
<table>
<tr>
<td>
<div>
<asp:TreeView ID=”myTreeView” runat=”server” ShowLines=”True” ExpandDepth=”1″ MaxDataBindDepth=”20″ PopulateNodesFromClient=”true”>
<ParentNodeStyle Font-Bold=”True” ForeColor=”#5555DD” />
<HoverNodeStyle Font-Underline=”False” />
<SelectedNodeStyle Font-Underline=”True” Font-Bold=”true” HorizontalPadding=”0px” VerticalPadding=”0px” />
<NodeStyle Font-Names=”Verdana” Font-Size=”8pt” ForeColor=”Black” HorizontalPadding=”5px”
NodeSpacing=”0px” VerticalPadding=”0px” />

</asp:TreeView>

</div>
</td>

<td></td></tr><tr><td><asp:Button ID=”Button1″ runat=”server” Text=”Button” OnClick=”TreeButton_Clicked”/></td></tr>
</table>

<dynamics:AxPopupChildControl ID=”TreeLookupChild” runat=”server”>
<dynamics:AxPopupField Name=”selectedName” />

</dynamics:AxPopupChildControl>

Code behind

using System;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls.WebParts;
using Microsoft.Dynamics.Framework.BusinessConnector.Proxy;
using Microsoft.Dynamics.Framework.BusinessConnector.Adapter;
using Proxy = Microsoft.Dynamics.Framework.BusinessConnector.Proxy;
using ApplicationProxy = Microsoft.Dynamics.Portal.Application.Proxy;
using Microsoft.Dynamics.Framework.BusinessConnector.Session;
using Microsoft.Dynamics.Framework.Portal.UI;

public partial class GDEPCustTreeView : System.Web.UI.UserControl
{
string nodename = “”;

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

private AxBaseWebPart WebPart
{
get { return AxBaseWebPart.GetWebpart(this); }
}

protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
displayTreeView();

}

WebPart.ModalDialogClosed += new EventHandler<AXModalDialogClosedEventArgs>(WebPart_ModalDialogClosed);
}

void WebPart_ModalDialogClosed(object sender, AXModalDialogClosedEventArgs e)
{
if (!string.IsNullOrEmpty(e.DialogArgs.Data))
{
string myName = e.DialogArgs.Data;

}
}
void displayTreeView()
{

String[] customers = (String[])ApplicationProxy.CustTable.getAllRecords();
try
{
int i = 0;
System.Web.UI.WebControls.TreeNode myTreeNode = new System.Web.UI.WebControls.TreeNode(“Customers”);
myTreeView.Nodes.Add(myTreeNode);
for (int j = 0; j<=customers.Length -1; j += 2)
{
string myAccountNum = customers[j].ToString();
string myName = customers[j + 1].ToString();

System.Web.UI.WebControls.TreeNode myTreeNodec = new System.Web.UI.WebControls.TreeNode(“Customer”);

//string custName = myAccountNum + ” ” + myName;
System.Web.UI.WebControls.TreeNode myTreeNode1 = new System.Web.UI.WebControls.TreeNode(myAccountNum);
System.Web.UI.WebControls.TreeNode myTreeNode2 = new System.Web.UI.WebControls.TreeNode(myName);
myTreeView.Nodes[0].ChildNodes.Add(myTreeNodec);
myTreeView.Nodes[0].ChildNodes[i].ChildNodes.Add(myTreeNode1);
myTreeView.Nodes[0].ChildNodes[i].ChildNodes.Add(myTreeNode2);

i++;

}
}
finally
{

}
}

protected void TreeButton_Clicked(object sender, EventArgs e)
{
System.Web.UI.WebControls.TreeNode childNode = myTreeView.SelectedNode;
string chName = childNode.Text;
TreeLookupChild.SetFieldValue(“selectedName”, chName);
TreeLookupChild.ClosePopup(true, true);

}
}

6. Host the above web part by creating new web page under the following module Sales/Enterprise%20Portal/GDEPCustTreeView.aspx.

7. Create the Web menu item url in Ax client for page of point – 6 (above page) – Save it, right click and import page.

8. Access the page with your EP url like, as an example is eg:http://dynamicsax.contoso.com/Sales/Enterprise%20Portal/GDEPCustomerFilter.aspx

Result of the above example.

EP Lookup Tree view

 



Viewing all articles
Browse latest Browse all 125409

Trending Articles