web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

get view from query

(0) ShareShare
ReportReport
Posted on by 320

How can I check what TreeNode object I have found?

Related topic: community.dynamics.com/.../get-the-query-from-view

static void GetViewFromQuery(Args _args)
{
#AOT
#define.QueryName(MainQuery)
#define.viewName('mainView')

TreeNode treeNode;
str tmp;
;
tmp = strFmt(#QueryPath + #AOTDelimiter + #ApplicationDataSourcesPath, identifierStr(#QueryName));
treeNode = TreeNode::findNode(tmp);
if (treeNode)
{
treeNode = treeNode.AOTfirstChild(); // Get the first data source -> view (as table)
if (treeNode)
{
tmp = treeNode.treeNodeName();

if (tmp == #viewName)
{
  info(strFmt("View %1 found", tmp));
}
}
}
}

The code above can be used to find the data source offset within a query. And yes it is possible to compare the name of the datasource to a name I already know....but I find that a erroneous way.

My question is how can I check if the found treenode is of type 'view'?

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,963 Most Valuable Professional on at

    First of all, let me add line indention to your code and use Insert > Code. Please do it by yourself next time. I also improved your code a little bit.

    static void GetViewFromQuery(Args _args)
    {
    	#AOT
    	#define.QueryName(MainQuery)
    	#define.viewName('mainView')
    
    	str queryNodePath = strFmt(#QueryPath   #AOTDelimiter   #ApplicationDataSourcesPath, identifierStr(#QueryName));
    	TreeNode treeNode = TreeNode::findNode(queryNodePath);
    	str nodeName;
    	
    	if (treeNode)
    	{
    		treeNode = treeNode.AOTfirstChild(); // Get the first data source -> view (as table)
    		if (treeNode)
    		{
    			nodeName = treeNode.treeNodeName();
    
    			if (nodeName == #viewName)
    			{
    				info(strFmt("View %1 found", nodeName));
    			}
    		}
    	}
    }

    To get what you need, get the table from the Table property of the node. Then you use SysDictTable to find whether this table is actually a view:

    SysDictTable::newName(tableName).isView();

    By the way, I wouldn't use TreeNode at all. Consider this approach instead:

    Query query = new Query(queryStr(mainView));
    QueryBuildDataSource firstDs = query.dataSource(1);
    SysDictTable::newTableId(firstDs.table()).isView();

  • botten Profile Picture
    320 on at

    Thanks Mister Dráb. The isView() did it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 478 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans