March 19, 2015

X++ code to find all the reports with datasources innerjoined 1:1

static void FindAllReports(Args _args)
{
   #AOT
   Report                  report;
   TreeNode                treeNode = TreeNode::findNode(#ReportsPath);
   TreeNodeIterator        iterator = treeNode.AOTiterator();
   QueryBuildDataSource    qbds;

   boolean  find1nInnerJoin(QueryBuildDataSource _qbdsParent)
   {
       int i;
       QueryBuildDataSource qbdsChild;
       boolean    ret;
       ;
       for (i = 1; i <= _qbdsParent.childDataSourceCount(); i++)
       {
           qbdsChild = _qbdsParent.childDataSourceNo(i);
           if (qbdsChild)
           {
               if (qbdsChild.joinMode() == JoinMode::InnerJoin &
& qbdsChild.fetchMode() == QueryFetchMode::One2One)//::One2Many)
                   return true;

               if (qbdsChild.childDataSourceCount() > 0 && find1nInnerJoin(qbdsChild))
                   return true;
           }
       }
       return ret;
   }
   ;

   treeNode = iterator.next();
   while (treeNode)
   {
       if (treeNode.sysNodeType() == 202) //Report
       {
           report = treeNode;
           if (report && report.query().dataSourceCount() > 1)
           {
               qbds = report.query().dataSourceNo(1);
               if (find1nInnerJoin(qbds))
                   info(report.name());
           }
       }
       treeNode = iterator.next();
   }
}


No comments:

Post a Comment