Ax 2012 EP Lookup as Tree view – Simple example
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 behindusing 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.
Custom Lookup for Dimensions in AX 2012 – for User Defined Dimensions
In this article, giving an example for defining the lookup for dimensions in simple way.
This example will cover only for user Defined dimensions.
For this
1) Created a form and added two string controls.
2) Named as
Control: Name: Dimensionlist, Auto declaration – Yes
Control: Name: DimValues
3) Override the lookup method for Dimensionlist
public void lookup()
{
Query query;
SysTableLookup sysTableLookup;
super();
sysTableLookup = SysTableLookup::newParameters(tableNum(DimensionAttribute), this);
sysTableLookup.addLookupfield(fieldNum(DimensionAttribute, Name));
query = new Query();
query.addDataSource(tableNum(DimensionAttribute)).
addRange(fieldNum(DimensionAttribute, Type)).
value(queryValue(DimensionAttributeType::CustomList));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
4) Override the lookup method for DimValues
public void lookup()
{
DimensionAttribute dimensionAttribute;
DimensionAttributeDirCategory dimAttributeDirCategory;
Query query = new Query();
SysTableLookup sysTableLookup;
dimensionAttribute = DimensionAttribute::findByName(Dimensionlist.text());
super();
// Only user defined dimensions will have a financial tag category
if (dimensionAttribute.Type == DimensionAttributeType::CustomList)
{
select firstonly DirCategory from dimAttributeDirCategory where dimAttributeDirCategory.DimensionAttribute == dimensionAttribute.RecId;
sysTableLookup = SysTableLookup::newParameters(tableNum(DimensionFinancialTag), this);
// Add name field to be shown in the lookup form.
sysTableLookup.addLookupfield(fieldNum(DimensionFinancialTag, Value));
sysTableLookup.addLookupfield(fieldNum(DimensionFinancialTag, Description));
query = new Query();
query.addDataSource(tableNum(DimensionFinancialTag)).
addRange(fieldNum(DimensionFinancialTag, FinancialTagCategory)).
value(queryValue(dimAttributeDirCategory.DirCategory));
sysTableLookup.parmQuery(query);
// Perform the lookup.
sysTableLookup.performFormLookup();
}
}
Run:
We can use the same concepts for Dimension controls on Ax 2012 SSRS reports dialog. To build the report dialog UI with dimension controls.
Report Server WMI Provider Error
The following article will be useful for two issues..
Error – 1: Report Server WMI Provider Error
Error – 2: Windows Management Instrumentation service is not running.
In my situation, suddenly report server stopped responding, after system and services are re-started.
Failed in trying to connect to Reporting services configuration manager and Reporting Services from SQL Server,
Facing the following error…
While searching for this issue, did not get exact answer for the above issue.
Tried to repair the report services installation by using SQL Server installation setup file, then found the following reason, in installation check list Windows Management Instrumentation service is not running.
Checked for the same in windows services, service is running, and no issues, successfully re-started also.
Still the same error during installation check list…..
With this error again started searching, got the following link as a solution to my issue.
http://apwot.blogspot.com/2008/09/windows-management-instrumentation.html
One or more office components failed to complete successfully sharepoint 2010
Have tried the installation of Sharepoint foundation 2010 and faced the above error.
Environment: Windows Server 2008 R2 Enterprise edition + SP1 , and SQL Server 2008 R2 + Sp1
Sharepoint foundation server 2010 installation is always pointing to the SQL Server Express
Log file can be find at the following path
C:\Users\<username>\AppData\Local\Temp
ERR:0:Fail to install or config SQL Express.
To get rid of this error, uninstall the sharepoint which is failed due to the above error.
Start again fresh installation by selecting the following (Server Farm) option…
Follow the wizard steps and sharepoint installation will successfully complete.
To Debug Ax Service Operations Framework
To debug the Dynamics Ax, service operations (SysOperationService) framework, change the following method as follows…
Classes –> SysOperationRPCFrameworkService –>runServiceOperation
/*return SysDictClass::invokeStaticMethodIL(classStr(SysOperationServiceController),
staticMethodStr(SysOperationServiceController, runServiceOperation),
[controllerClassId, packedController]);*/
return SysOperationServiceController::runServiceOperation([controllerClassId, packedController]);
Save The SRS Printer Settings in Table and Re-Use
In this article,
1) We can store the printer settings of a report in the table, like in parameters table as a container type field. (Section –I)
2) While printing the reports, we will read the settings from the parameter table and we will apply the same for report printing. (Section – II)
static void myPrinterSettingsReport(Args _args)
{
SrsPrintDestinationSettings printSettings;
FormRun printSettingForm;
boolean ok = true;
Args args = new Args();
container myPrint;
SrsReportRun reportRun;
SRSPrintDestinationSettings srsPrintSettings;
//Section – I
//This we can implement on the parameters form by adding button and define this in click event
printSettings = new SrsPrintDestinationSettings();
args.caller(printSettings);
//calling printersettings form
args.name(formstr(SRSPrintDestinationSettingsForm));
printSettingForm = classfactory.formRunClass(args);
printSettingForm.init();
printSettingForm.run();
printSettingForm.wait(true);
ok = printSettingForm.closedOk();
if (ok)
{
//Retrieving printer settings to a container and this container we can store in to a table
myPrint = printSettings.pack();
}
//Section –II
reportRun = new SRSReportRun();
reportRun.reportName(“Vend.Report”);
// Set printersettings
srsPrintSettings = reportRun.printDestinationSettings();
// while generating the report we can read the printersettings from table (container field value) and pass to the following method.
srsPrintSettings.unpack(myPrint);
reportRun.showDialog(false);
reportRun.init();
reportRun.savePrinterSettings(false);
reportRun.saveReportParameters(false);
reportRun.saveReportQueries(false);
reportRun.run();
}
Ax 2012 Reports (SSRS) Print Utilities
This article gives the examples, to print the reports of Dynamics Ax 2012 (SSRS Reports), in different ways.
1)Sending the Ax report through mail.
2)Save the report as file in local computer. (example covered to save the report as .pdf file)
Mail the report
static void myJobPrintReportMail(Args _args)
{
SrsReportRun reportRun;
Query query;
SRSReportPrintDestinationSettings SRSReportPrintDestinationSettings;
SRSPrintDestinationSettings srsPrintSettings;
;
delete_from SRSReportPrintDestinationSettings;
reportRun = new SRSReportRun();
reportRun.reportName(“Vend.Report”); //<ReportName>.<DesignName>
// Set printersettings
srsPrintSettings = reportRun.printDestinationSettings();
srsPrintSettings.printMediumType(SRSPrintMediumType::Email);
srsPrintSettings.emailTo(“mail@gmail.com”);
srsPrintSettings.emailAttachmentFileFormat(SRSReportFileFormat::PDF);
srsPrintSettings.emailSubject(strfmt(‘vendor report – %1’, systemdateget()));
srsPrintSettings.pack();
reportRun.showDialog(false);
reportRun.init();
reportRun.run();
}
Save the Report To PDF File
static void myJobPrintReportPDF(Args _args)
{
SrsReportRun reportRun;
SRSPrintDestinationSettings srsPrintSettings;
SRSReportPrintDestinationSettings SRSReportPrintDestinationSettings;
;
delete_from SRSReportPrintDestinationSettings;
reportRun = new SRSReportRun();
reportRun.reportName(“Vend.Report”); //<ReportName>.<DesignName>
// Set printersettings
srsPrintSettings = reportRun.printDestinationSettings();
srsPrintSettings.overwriteFile(true);
srsPrintSettings.printMediumType(SRSPrintMediumType::File);
srsPrintSettings.fileFormat(SRSReportFileFormat::PDF);
srsPrintSettings.fileName(“D:\\Vendors.pdf”);
srsPrintSettings.pack();
reportRun.showDialog(false);
//reportRun.saveParameters(); //For Report parameters
reportRun.init();
reportRun.run();
}
In case of Parameterized reports
If the report has parameters (Using Contract Class),
Use the following line, to read the parameters and save to the table called, SRSReportParameters
reportRun.saveParameters();
For the same parameters, provide the required values to run the report.
I have tried the example of Vendor Transactions report, with my customized version. This standard report has 4 parameters, have used same parameters and provided the values in SRSReportParameters table to run the report.
For clear idea, have a quick look in to the following picture.
My experience on Dynamics Ax 2012 EP Installation
Started working on Ax 2012, and recently installed the Enterprise portal (EP) in my system.
OS is Windows 7 Enterprise edition.
SharePoint Foundation 2010 can be downloaded from the following link.
http://www.microsoft.com/en-us/download/details.aspx?id=5970
I have downloaded the same, and tried the installation (by running .exe directly)… but have seen the following error.
Then, as a routine goggled for the issue, got the following link….
http://msdn.microsoft.com/en-us/library/ee554869(office.14).aspx
By following the above link, successfully installed the SharePoint and completed the EP installation also.
Dimension (Field Value) Search Utility in Dynamics Ax
In recent days, I got a specific requirement…
At our place, finance controller has decided to close one dimension value and need to replace the same with new dimension value.
To support this, we need to update all the transactions which have old dimension value, to new one.
Assume all the transactions, which are created Dimension [10] – Business unit with value 201, need to update as 203
static void ininspar_Dimension201_Update_Alltables(Args _args)
{
TreeNode tn,fn;
TreeNodeIterator tni,fni,_tni;
Str objName;
SysDictField sysDictField;
Common common;
Query query = new Query();
QueryBuildDataSource qbs;
QueryBuildRange qbr;
TableId mTableId;
QueryRun qr;
;tn = TreeNode::findNode(“\\Data Dictionary\\Tables”);
tni = tn.AOTiterator();
tn = tni.next();while (tn)
{
objName = tn.treeNodeName();tn = tni.next();
mTableId = tableName2id(objName);
sysDictField = new SysDictField(mTableId, fieldname2id(mTableId, “Dimension”)); // Finding table object which have Dimension fieldif (sysDictField && Global::hasTableAccess(mTableId))
{
//info(objname);
try
{
qbs = query.addDataSource(mTableId);
qbr = qbs.addRange(fieldId2Ext(fieldname2id(mTableId, “Dimension”),10)); // using Dimension[10] in query range
qbr.value(“201”);qr = new QueryRun(query);
while (qr.next())
{common = qr.get(mTableId);
if (common.RecId)
{
common.selectForUpdate(true);
ttsbegin;
common.(fieldId2Ext(fieldname2id(mTableId, “Dimension”),10)) = “203”; //assigning the Dimension[10] value by using Common
common.update();
ttscommit;
info(strfmt(“%1 %2”,objName, int2str(common.RecId)));
}
}
}
catch(Exception::Error)
{
continue;
}}
}
}
With this, we can write some Advanced Search utilities, to find specific values for some fields for the tables.
AIF – Update – The parameter index is not valid
In recent days, working on AIF – Update action, and find one strange error as mentioned below.
Error: The parameter index is not valid.
Trying to solve the same, and then have checked on the parameter schema, it was defined as follows…
So realized, we need to submit two XML’s for the update scenario, or combination of these two required and then tried in the following way…
<Envelope xmlns=”http://schemas.microsoft.com/dynamics/2008/01/documents/Message”>
<Header><MessageId>{FDA1E99A-3519-458D-6DE7-8A4502322BF1}</MessageId><SourceEndpointUser>domain\aliasId</SourceEndpointUser>
<SourceEndpoint>DimensionsInbound</SourceEndpoint><DestinationEndpoint>USEndpoint</DestinationEndpoint>
<Action>http://schemas.microsoft.com/dynamics/2008/01
/services/Tel_DimensionsService/update</Action></Header>
<Body>
<MessageParts xmlns=”http://schemas.microsoft.com/dynamics/2008/01/documents/Message“>
<EntityKeyList xmlns=”http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKeyList“>
<EntityKey xmlns=”http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKey“>
<KeyData>
<KeyField>
<Field>DimensionCode</Field>
<Value>Department</Value>
</KeyField>
<KeyField>
<Field>Num</Field>
<Value>2030</Value>
</KeyField>
</KeyData>
</EntityKey>
</EntityKeyList>
<Tel_Dimensions xmlns=”http://schemas.microsoft.com/dynamics/2008/01/documents/Tel_Dimensions“><Dimension>
<_DocumentHash>820acb9d4e266e791f5069edd7bd3d39</_DocumentHash>
<Closed>No</Closed><CompanyGroup>12345</CompanyGroup><Description>IN Global Support India – TEST123456</Description>
<DimensionCode>Department</DimensionCode>
<Num>2030</Num></Dimension></Tel_Dimensions></MessageParts></Body></Envelope>