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'?

  • botten Profile Picture
    botten 320 on at
    RE: get view from query

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

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: get view from query

    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();

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans