MCTS: 70-573 SharePoint 2010 Application Development

image

On Friday 13th Smiley I was certified for SharePoint 2010 Application Development. Since every Dynamics AX Silver+ Partner need at least on SharePoint guy, I’m the one for InsideAx. I’m already experienced in maintaining SharePoint 2012 (mainly Foundation) for those of our Customers running Rolecenter in AX 2009. Furthermore I’ve upgraded and developed Enterprise Portal applications in the last two years. However, EP development and classic SharePoint development does diverge. Everybody who ever tried to modify EP using SharePoint designer knows what I’m taking about.

I don’t want to say that all the cool SharePoint features cannot be used to extend Dynamics AX (e.g. I’ve built a web based appointment app using SharePoint and its lists and calendars to visualize the schedules). All those who are now forced to get in touch with SharePoint may experience that it can be used in may cases to provide cool solutions for their customers. But I’d like Microsoft to strengthen the web / enterprise portal development aspect of Dynamics AX by extending the development course materials and provide an Enterprise Portal Certification.

Enterprise Portal Custom Filter Error after a short time

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.

Microsoft.Dynamics.Framework.BusinessConnector.Session.Exceptions.NoKernelSessionException

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

Color Rows in Enterprise Portal AxGridView

image

  1. Create a new display method webBackgroundColor at InventTable

    public display Color webBackgroundColor()
    {;
        switch(this.ItemType)
        {
            case ItemType::BOM:     return "Red";
            case ItemType::Item:    return "Green";
            case ItemType::Service: return "Blue";
            default: return "White";
        }
    }

  2. Create a new Dataset and add InventTable as DataSource
  3. Create or open a new Dynamcis Ax web project in Visual Studio
  4. Create or open an AxWebUserControl and add an AxDataSource using InventTable data set from AX
  5. Add an AxGridView and link it with the AxDataSource
  6. Add webBackroungColor**, ItemId and ItemName to the grid
    image
  7. Select the AxGridView, change to events and modify the RowDataBound event

    protected void AxGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        string axColor = e.Row.Cells[0].Text.ToLower();
       
        if(axColor.Equals("red"))
            e.Row.BackColor = System.Drawing.Color.Red;
        else if(axColor.Equals("green"))
            e.Row.BackColor = System.Drawing.Color.Green;
        else if(axColor.Equals("blue"))
            e.Row.BackColor = System.Drawing.Color.Blue;       
    }

  8. Load the user control in an enterprise portal site

Use an Extended Datatype (Color instead of str) for the display method, otherwise you may experience strange behaviour in your ASP.NET application.