Hope you are doing well.
Recently, I did an Enterprise Portal code upgrade for one of my customers. They are on Dynamics AX 2009 and as I was investigating, I found that the web forms of Dynamics AX 4.0 were not upgraded by their previous vendor, so I undertook the task of upgrading their 20+ web forms (Dynamics AX 4.0) to Dynamics AX 2009 web controls.
I had to replace the existing standard filters which comes with EP AxGridView to custom textbox filters. And, for this reason I had to apply the filters via code. I got a good idea by seeing this useful blog on how to achieve it http://blogs.msdn.com/b/epblog/archive/2008/11/17/filtering-a-dataset-from-code-behind.aspx
There was a small hiccup while referencing FilterCondition and Typ as I didn't knew the namespace, so before we use the filterObject and conditionType objects, dont forget to declare the below highlighted namespace.
using Microsoft.Dynamics.Framework.Data.Ax;
Microsoft.Dynamics.Framework.Data.Ax.filterObject
Microsoft.Dynamics.Framework.Data.Ax.conditionType
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Data.Ax; | |
if (txtName.Text != "") | |
{ | |
Microsoft.Dynamics.Framework.Data.Ax.filterObject flt = new filterObject(); | |
flt.name = "NameFilter"; | |
Microsoft.Dynamics.Framework.Data.Ax.conditionType typ = new conditionType(); | |
typ.__operator = Microsoft.Dynamics.Framework.Data.Ax.operatorType.like; | |
typ.status = Microsoft.Dynamics.Framework.Data.Ax.conditionStatus.open; | |
typ.value = txtName.Text; | |
typ.attribute = "Name"; | |
flt.conditionCollection.Add(typ); | |
dsv.UserFilter.Add(flt); | |
} |
2 comments:
Hello,
Very useful post.
What is the syntax to identify one the dimension field:
typ.attribute = "Dimension[3]"
returns an error, same with other variations:
Dimension3_
Dimension3
Dimension_3
There must be a way to use one of the dimension field.
We're on Ax 2009 (until September!)
Regards,
The namespace has changed from to "using Microsoft.Dynamics.AX.Framework.Portal.Data;".
So the code itself will look as following:
dsv.UserFilter.ClearOpenFilter();
filterObject flt = new filterObject();
flt.name = "NameFilter";
conditionType typ = new conditionType();
typ.__operator = operatorType.like;
typ.status = conditionStatus.open;
typ.value = lb.Text;
typ.attribute = "Name";
flt.conditionCollection.Add(typ);
dsv.UserFilter.Add(flt);
Post a Comment