Help with query to fill grid when form loads

Hi, please any help would be greately appriciated!

I’m a newbie to AX 2012 development, trying to customize the All Purchase Requisitions grid, please check attached image1 for what I’m trying to do.

I’ve got 3 tables that I need to join so I can display fields from the 3 on a grid for All Purchase Requisitions, especially fron the WorkflowWorkItemTable that has the name of the person that currently has the requisition for any of the status (closed, riview, approved, draft)

PurchReqTable → RecID

PurchReqLine → PurchReqTable

WorkflowWorkItemTable → RefRecId

The class PurchReqTableForm to fill the form, the definition is:

///

/// The PurchReqTableForm class controls the behavior of the PurchReqTable form.

///

class

PurchReqTableForm implements

SysSaveable

{

PurchReqTable purchReqTable;

PurchReqId newPurchReqId;

PurchReqLine newlyCreatedPurchReqLine;

PurchReqShowRequisitions showRequisitions;

RecId requisitionerRecId;

HcmWorkerName requisitionerName;

PurchReqRequisitionStatus status;

NoYes statusAll;

QueryBuildRange rangeRequisitioner;

QueryBuildRange rangeStatus;

QueryBuildDataSource joinWorkFlowItemTable;

FormDataSource queryPurchReqTable;

FormDataSource queryPurchReqLine;

FormDataSource queryWorkflowWorkItemTable;

boolean

isFormLoading;

QueryBuildDataSource purchReqTableFilterDataSource;

boolean

isFilterHeaderOriginator;

PurchReqFormMode purchReqFormMode;

container

packedClasses;

ProjTable projTable;

PurchReqShowRequisitionsFilter purchReqShowRequisitionsFilter;

AccountingDistributionView distributionView;

Object purchReqTableFormRun;

#DEFINE.Project(

‘Project’

)

#define.CurrentVersion(

4

)

And the query to fill the grid on the form is below, I do not get any error message after I added the code to join the WorkflowWorkItemTable with the original 2 tables, because this table has the name I want to display on the grid when the form loads:

public

Query queryPurchTable(FormDataSource _queryPurchReqTable, FormDataSource _queryPurchReqLine, FormDataSource _queryWorkflowWorkItemTable, boolean

_isFilterHeaderOriginator)

{

QueryBuildDataSource qbdsTable = _queryPurchReqTable.query().dataSourceTable(

tableNum

(PurchReqTable));

QueryBuildDataSource qbdsLine = _queryPurchReqLine.query().dataSourceTable(

tableNum

(PurchReqLine));

QueryBuildDataSource qbdsWorkIT = _queryPurchReqLine.query().dataSourceTable(

tableNum

(WorkflowWorkItemTable));

rangeRequisitioner = qbdsLine.addRange(

fieldNum

(PurchReqLine, Requisitioner));

rangeRequisitioner.status(RangeStatus::Locked);

rangeRequisitioner.enabled(

false

);

rangeStatus = qbdsTable.addRange(

fieldNum

(PurchReqTable, RequisitionStatus));

rangeStatus.status(RangeStatus::Locked);

this.setStatus(status, statusAll);

queryPurchReqTable = _queryPurchReqTable;

queryPurchReqLine = _queryPurchReqLine;

queryWorkflowWorkItemTable = _queryWorkflowWorkItemTable;

isFilterHeaderOriginator = _isFilterHeaderOriginator;

purchReqShowRequisitionsFilter = PurchReqShowRequisitionsFilter::newPurchReqTable(qbdsTable, qbdsLine,

fieldNum

(PurchReqLine,Requisitioner), isFilterHeaderOriginator);

purchReqShowRequisitionsFilter.applyFilter(showRequisitions);

purchReqTableFilterDataSource = qbdsTable.addDataSource(

tableNum

(PurchReqLine));

purchReqTableFilterDataSource = qbdsTable.addDataSource(

tableNum

(WorkflowWorkItemTable));

purchReqTableFilterDataSource.enabled(

false

);

purchReqTableFilterDataSource.addLink(

fieldNum(PurchReqTable, RecId), fieldNum

(PurchReqLine, PurchReqTable));

purchReqTableFilterDataSource.addLink(

fieldNum(PurchReqTable, RecId), fieldNum

(WorkflowWorkItemTable, RefRecId));

purchReqTableFilterDataSource.joinMode(JoinMode::ExistsJoin);

return

_queryPurchReqTable.query();

If you want to add additional data sources, I would expect you to change the PurchTableListPage query. If you add them at run-time, you won’t be able to bound the grid field to a datasource at design-time, will you?

Hi Martin,

Please take a look, I`ve finally found the tables I need to add to the query PurchReqTableListPage that’s used to fill the form PurchReqTableListPage, now te query simply pulls all the records from the PurchReqTable, to get the field I need I must add to the query a second Datasource from the table WorkflowWorkItemTable.

I’ve found this code, try to overide the query init method but got an error, please take a look at this code, I’m not sure where to pu it or if it is the correct way to go about it.

Query query;
QueryBuildDatasource datasource;

query = new Query();

// Add main datasource
datasource = query.addDataSource(tableNum(PurchReqTable));

// Add child datasource
datasource = datasource.addDataSource(tableNum(WorkflowWorkItemTable));

// Set the join mode
datasource.joinMode(JoinMode::InnerJoin);

// Indicate you don’t want to use relations automatically
datasource.relations(false);

// Add link between parent field and child field
datasource.addLink(fieldNum(PurchReqTable, RecId),
fieldNum(WorkflowWorkItemTable, RefRecId));

super();

I’m running AX2012, using the OAT did not show any properties to add join mode, or links, the above mention 2 tables must be linked on the parent table PurchReqTable → RecId , on the chile table WorkflowWorkItem → RefReqId

Thanks in advanced for your help.

I have no idea how writing any code would help you. Could you please explain to me how you’re going to display a field in the grid if the data source is added in code?