web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to show data in a grid on Enteprise Portal 2012 from a ResultSet

(0) ShareShare
ReportReport
Posted on by

When you use the quick filter search in a grid on Enterprise Portal, the result you are presented are sorted by recid. If you search for "a blue car" on a field e.g. "Item description" the exact record where item description is "a blue car" is found several records below the top record. In my situation, this is not appropriated since I need it to sort according to "best match". I also need it to sort by stemming but this can be done by using Full Text Index on a table.

After searching around the web, I found a part of the solution by executing direct SQL statements from X++ and this is what I came up with (Proof of concept and thx to this author community.dynamics.com/.../executing-direct-sql-statements):

static void PMP_DirectSQL(Args _args)
{
    Connection                      connection;
    Statement                       statement;
    str                             query;
    str                             criteria = "affaldspose";
    Resultset                       resultSet;
    SqlStatementExecutePermission   sqlPerm;

    // create connection object
    connection = new Connection();

    // Set the SQL statement
    query = "SELECT ItemId, ItemName, NameAlias, Rank FROM dbo.FULLTEXTINDEXTABLE_TEST AS FT_TBL INNER JOIN FREETEXTTABLE(dbo.FULLTEXTINDEXTABLE_TEST, ItemName, '" + criteria +"', LANGUAGE N'Danish') AS KEY_TBL ON FT_TBL.RECID = KEY_TBL.[KEY] ORDER BY RANK DESC;";

    // assert SQL statement execute permission
    sqlPerm = new SqlStatementExecutePermission(query);
    sqlPerm.assert();

    // create statement
    statement = connection.createStatement();

    // when the query returns result,
    // loop all results for processing
    //BP Deviation documented
    resultSet = statement.executeQuery(query);

    while(resultSet.next())
    {
        // do something with the result
        info(strFmt("%1, %2, %3, %4",   resultSet.getString(1),
                                        resultSet.getString(2),
                                        resultSet.getString(3),
                                        resultSet.getString(4)));
    }

    resultSet.close();
    statement.close();
    // limit the scope of the assert call
    CodeAccessPermission::revertAssert();
}

The job above will search for everything that contains "affaldspose" <-- danish for "waste bag" and rank the result according to best match.

Moving on, i created a temp. table, populate the table with data from the resultset and used it in a dataset so that I could use it on a grid in a user control, but then I saw this statement "TempDB tables can be used by forms, and in X++ code that is not tied to any user interface. But TempDB tables cannot be used directly by Enterprise Portal data sets." from there https://msdn.microsoft.com/en-us/library/gg845661.aspx 

So the question from the subject: How to show data in a grid on Enteprise Portal 2012 from a ResultSet? one possible solution is to store the result in a physical table and delete the records after the session has ended, but i'm thinking is not a good solution.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Iulian Cordobin Profile Picture
    8,201 on at

    I also didn't know about this limitation, but I will try for sure to see what kind of errors this throws and see why it can't be used.

    Moving further with your inquiry, I will only say that the approach to inquiry the database directly without the help of the Data Dictionary objects is not that well thought of, but, if you have clear requirements and this is solving them, then that's that. Now, the solution for you can be either of the two:

    1) just use as you say a normal table to insert your results into, managing of course the data content with the help of some GUIDs for each user's session; at the end of the day this is not necessarily a bad approach and people do use it.

    or

    2) just make the temporary table InMemory rather than TempDB. InMemory tables can be used in EP, and it will solve your issues with data content management.

  • Community Member Profile Picture
    on at

    The reason why I'm using direct calls is to utilize stemming and free text search. I'm aware that AX 2012 is now capable of full text search, but the limitation is the result is returned in recID order. Currently I'm not aware of other possible solutions when searching in an EP grid utilizing free text and stemming.

    I'm thinking on going with your second solution, but where would you populate the data and how? I've a data set (MyDataSet) with the inMemory table as datasource the datasource (MyTable).

  • Iulian Cordobin Profile Picture
    8,201 on at

    I would go with the DataSet in the Init method.

  • Community Member Profile Picture
    on at

    But the init method will only be called once? Wouldn't I get a problem when the range is changed?

    I tried to modify the executeQuery() method on the datasource with this, code:

       public void executeQuery()

       {

           //Create instance of class

           FullTextSearch_Test obj = new FullTextSearch_Test();

           //Fill temp table with data

           inventTableTemp = obj.populateTempTable(inventTableTemp);

           //set temp data on datasource from temp. table

           InventTableTemp_Test.setTmpData(inventTableTemp);

           super();

       }

    This approach will show me the data I needed on the grid on enterprise portal, but I don't know about the limitation of this approach. The reason why i'm doing so is for later on, when I manage to get the values from user specified range, I can fill my temp table with new data according to the resultset.

  • Community Member Profile Picture
    on at

    inventTableTemp is declared in classDeclaration on the dataset :)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans