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, ...
Suggested Answer

while select crosscompany with empty container executes for ALL companies

(1) ShareShare
ReportReport
Posted on by 14
Hi to all!
 
I was working with intercompany query and based on some parameters I have to execute a query for specific companies only.
 
From standard documentation I see the syntax for 'while select crosscompany' can accept a container specifying for which companies it should execute.
Syntax is as follows: 'while select crosscompany : myContainer'.
 
In my implementation it is a valid scenario that the query should not execute if 'no company' was selected.
I though that passing an empty container to the above syntax would skip the query entirely, but apparently it executes for ALL companies (same as the no-container syntax).
 
Easy to fix with an 'if' before the query, but I am surprised and find the behavior counter-intuitive.
I could not find any confirmation of this behavior.
Can someone point to a similar example (even STD code) or confirm my finding?
 
Thank you all!
I have the same question (0)
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,811 Super User 2026 Season 1 on at
    Hi,
     
    In your case the container is an option(Not required) in select statement.
    you can write the select statement without container.
    if it is empty I think it will be considered as null.
    Please refer to official documentation 
     
    Best regards,
    Mohamed Amine MAHMOUDI
  • Suggested answer
    Layan Jwei Profile Picture
    8,282 Super User 2026 Season 2 on at
    Hi Community member,

    I didn't try it before, but if you are saying an empty container is returning data from all companies, then indeed you can use an if condition OR you can specify the legal entities you are interested with in the select statement, so that if no match is found nothing is returned, i mean sth like this: (while select crosscompany table1 where dataAreaId = USMF ||  dataAreaId = DAT)

    Check this link for more info about cross-company
    https://ontargit.com/en/working-with-intercompany-functionality/

    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • LC-29041152-0 Profile Picture
    14 on at
    Hi to all, thanks for your answers.
     
    Solution is straight forward for me, I can check for empty container and return before executing the query.
     
    Unfortunately suggested solution in adding the companies as a range is not doable as the container content is not fixed. To allow to construct a proper range I should loop the container and build the query with QueryRun and QueryBuildDataSource, which now will be quite some work (I have three big queries with this requirement).
     
    Again, unfortunately standard documentation does not specify the behavior with an empty container. I though the encountered behavior was counter-intuitive, but apparently nobody used it as I did yet.
     
    Anyway, I hope this post will be useful as reference to other for the future :)

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
Martin Dráb Profile Picture

Martin Dráb 265 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Subra Profile Picture

Subra 229 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans