Blog

Name is Anant Dubey and the intent to create this blog is to discuss the problems and issues that developer face in the dynamics AX development and to share the new things that come up with the new version of AX.

Monday, 13 January 2014

Worker Phone With Name Filter in ax 2012

static void S_WorkerPhone(Args _args)
{
    TreeNode                    treeNode;
    Query                       q;
    QueryBuildDataSource        qbds,qbds1,qbds2,qbds3;
    QueryRun                    qr;
    QueryBuildRange             qbr;
    HcmWorker                   hcmWorker;
    DirPerson                   dirPerson;
    DirPartyTable               dirPartyTable;
    LogisticsElectronicAddress  logisticsElectronicAddress;
    str                         queryname = "S_WorkerPhone";
    str                         projectName = "A_DemoQuery";
    ;
    #AOT
    // Delete the query from the AOT, if the query exists.

    treeNode = TreeNode::findNode(#QueriesPath);
    //treeNode = treeNode::findNode(#ProjectPrivatePath);
    treeNode = treeNode.AOTfindChild(queryname);
    //treeNode = treeNode.AOTfindChild(queryname);
    if (treeNode)
    {
        //treeNode.AOTDuplicate();
        //treeNode.newObjectName(queryname);
        treeNode.AOTdelete();
    }

    treeNode = TreeNode::findNode(#QueriesPath);
    //treeNode = treeNode::findNode(#ProjectPrivatePath);
    //treeNode = treeNode.AOTfindChild(projectName);
    //treeNode = treeNode.AOTfindChild(queryname);
    treeNode.AOTadd(queryname);
    q                   = treeNode.AOTfindChild(queryname);
    //q                   = treeNode.AOTfindChild("S_WorkerPhone");
    qbds                = q.addDataSource(tableNum(DirPerson));
    qbds1               = qbds.addDataSource(tableNum(DirPartyTable));
    qbds2               = qbds1.addDataSource(tableNum(LogisticsElectronicAddress));
    //qbds3               = qbds1.addDataSource(tableNum(LogisticsElectronicAddress));
    //qbr                 = qbds.addRange(fieldNum(HcmWorker,personnelNumber));
    //qbds1.addLink(fieldNum(DirPartyTable,RecId),
    //              fieldNum(DirPerson,RecId));
    qbds1.addLink(fieldNum(DirPerson,RecId),
                  fieldNum(DirPartyTable,RecId));
    qbds2.addLink(fieldNum(LogisticsElectronicAddress,RecId),
                  fieldNum(DirPartyTable,PrimaryContactEmail));
                 /* && fieldNum(DirPartyTable,primaryContactPhone),
                     fieldNum(LogisticsElectronicAddress,RecId));*/
    //qbds2.addDynalink(fieldNum(LogisticsElectronicAddress,RecId),
    //                  fieldNum(DirPartyTable,primaryContactEmail));
    //qbds2.addLink(fieldNum(LogisticsElectronicAddress,RecId),
    //              fieldNum(DirPartyTable,primaryContactemail));
    //            (fieldNum(DirPartyTable,RecId)));
    //qbds3.addLink(fieldNum(DirPartyTable,primaryContactPhone),
    //              fieldNum(LogisticsElectronicAddress,RecId));
    q.AOTcompile(1);
    q.AOTsave();
    qr = new QueryRun("S_WorkerPhone");
    while(qr.next())
    {
        dirPerson                    = qr.GetNo(1);
        dirPartyTable                = qr.getNo(2);
        logisticsElectronicAddress   = qr.getNo(3);
        //logisticsElectronicAddress   = qr.getNo(4);
        //hcmWorker       = qr.get(tableNum(HcmWorker));
        info(strFmt("%1, %2, %3",dirPerson.Name,logisticsElectronicAddress.Locator,dirPartyTable.primaryPhone()));
    }
}