Enterprise Portal Custom Filter Error after a short time
15. August 2011 Leave a comment
Again I experienced a strange behavior within Dynamics AX 2009 Enterprise Portal. I’ve created a AxGridView using an AxDataSource connected to a DataSet in Dynamics AX. The DataSet holds a setFilter method to set values on some QueryBuildRanges. Moreover I’ve create a button in my AxUserControl Webpart that invokes the setFilter method with some values.
protected void SearchButton_Click(object sender, EventArgs e)
{
string value1 = TextBox1.Text;
string value2 = TextBox2.Text;
AxDataSourceMyTable.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call
(“setFilter”,value1,value2);
}
public void setFilter(str _value1, str value2)
{;
qbrSomeField.value(_value1);
qbrAnotherField.value(_value2);
MyTable_DS.executeQuery();
}
This implementation worked fine the first time using the webpart. However, after a very short time I got an error telling me that no Business Connector Session was found.
First I thought of some kind of timeout and played with IIS settings. But Google found this discussion where it is explained that Dynamics AX deletes the QueryBuildRange objects after a very short time, and therefore the call fails. The solution is to use SysQuery::findOrCreateRange .
public void setFilter(str _value1, str value2)
{
QueryBuildDataSource qbds;
;
qbds = MyTable_DS.query().dataSourceTable(tableNum(MyTable))
SysQuery::findOrCreateRange(qbds,fieldNum(MyTable,Field1)).value(_value1);
SysQuery::findOrCreateRange(qbds,fieldNum(MyTable,Field2)).value(_value2);
MyTable_DS.executeQuery();
}