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

Announcements

News and Announcements icon
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
    240,275 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 310 Super User 2026 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 276 Most Valuable Professional

#3
Anton Venter Profile Picture

Anton Venter 266 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans