Search code examples
containersaxaptax++dynamics-ax-2012

How to use container or generic variable in a query?


It's possible to use string value in a Query?

I have this code in my Form init method:

container con;

select myTable
where myTable.MyFIeld == conPeek(con, 1);
//I would like to fill my stringEditControl
StringEdit.text(strFmt('%1', myTable.MyFIeld));

I have an error look like this:

"The fields of type string container and unconstrained are not allowed in the WHERE expression."

How can I use the value string or container (in this case) in a query?

Thanks for your time,

enjoy!


Solution

  • Extract the string from container prior to using it is select statement:

    MyTable   myTable;
    container con;
    str 50 strValue;
    
    strValue = conPeek(con, 1);
    
    select myTable
    where myTable.MyField == strValue;
    
    StringEdit.text(strFmt('%1', myTable.MyFIeld));