To do this you need to:
1. Create a field in your table of type container;
2. Create the query, you want to initially display to the user, as usual from the AOT;
3. Use the following code:
void createAndSaveQueryInTable()
{
  QueryRun queryRun;
  YourTable yourTable;
  ;
  // Attach new queryRun object to AOT Query
  queryRun = new QueryRun(queryStr('YourQuery'));
  // Display the query to the user for him/her to make the necessary changes
  if (queryRun.prompt())
  {
    // Save the packed query to the database
    // Pack the queryRun so that it can be saved in the table
    yourTable.QueryContainerField = queryRun.pack();
    yourTable.insert();
   }
}
Now, to retrieve the saved query from the table, for some other use, is equally simple:
void retrieveQueryFromTable()
{
  Container packedQuery;
  YourTable yourTable;
  ;
  // Get the necessary record from the table
  yourTable = YourTable::find(......);
  // Get the query stored in the table in packed form
  packedQuery = yourTable.QueryContainerField;
  // check if you already have a query packed in your field
  if (packedQuery)
  {
    // Unpack it into a queryRun
    queryRun = new QueryRun(packedQuery);
  }
  else
  {
    // Call method to create a new query - method shown in code snippet above
    queryRun = this.createAndSaveQueryInTable();
  }
  // Do any cool work with your QueryRun here
  // .....
}
If you any questions or comments e-mail me on: mirko@mirkobonello.com
1 comment:
Hello. This is nice blog!
Post a Comment