Hi
I have made a little modification to our Ax 4 but have run into a problem I can't figure out. I have a table with a tablenum reference and a field num reference. This lets the user select a table and a field for further validation (in validateWrite) - like a dynamic validation rule. This works fint.
I now have added a query to the rule to let the user select when the rule should be active based on this query (on the same table)
Now I'm trying to write the code for this, but I keep running into the problem that I can't use the query directly as this works on the table on the SQL server and I need to validate BEFORE the record is written.
I have come up with something like this:
static boolean recordInQuery(Query q, common record)
{
QueryBuildDatasource qbd;
QueryBuildRange qbr;
int i;
boolean ret = false;
;
if (q.dataSourceCount() != 1) throw error("Too many tables!"); // Only one table in the query is allowed
qbd = q.dataSourceTable(record.TableId);
if (qbd) // If query does not contain the correct table - the record is definetly not found
{
ret = true;
for (i=0; i<qbd.rangeCount(); i++) // Loop through all ranges
{
qbr = qbd.range(i);
if (record.(qbr.field()) != qbr.value()) // No good! Need to test value for "!" and ".." etc
{
ret = false;
}
}
}
return ret;
}
Anyone who can create the code for the actual testing of the field?
E.g. if the user writes a query containing "1.." or "1..87" or "!34" the record should be found if the testet field has the value of 42