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

Intercompany orders

(6) ShareShare
ReportReport
Posted on by 171
Hello, 
 
I am trying to create a simple list screen that will list intercompany PO-SO orders where their statuses are not in synch.  I found tables to use and was able to verify the SQL to use in SQLDB (as inner join). But when I used it in X++, using query or override to executeQuery, I am not getting any information back from the IC sales order and only works as outer join.  My main data source is purchTable.  I am using fields intercompanycompanyid and intercompanysalesid, to map the record to salesTable.  Is there a special setting on the Xpp side that I missed?  
 
Thanks in advance! 
 
 
 
Categories:
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,660 Most Valuable Professional on at
    Moved from Integration, Dataverse, and general topics forum.
     
    The problem likely is that you forgot to make the query intercompany and therefore it fetches data from the current company only, while you want two different companies.
     
    Your screenshot shows that you're actually talking about a form; there you can use Cross Company Auto Query property of the form data source. You'll then likely want to filter PurchTable data source by curExt().
  • MacNeg Profile Picture
    171 on at
    Thanks Martin for the response. I updated my forms and set the "Cross company auto query" property to Yes and still did not display IC SO information.  I enabled it to both purchtable and salestable ds. 
     
  • Martin Dráb Profile Picture
    239,660 Most Valuable Professional on at
    Try also Set Company property of the form design.
     
    In general, it's benefial to check what query you've generated by your setup and X++ code, not just looking at what the query returns. When you see that there is (say) a wrong filter or a join condition in the SQL statement, you know what to focus on.
  • MacNeg Profile Picture
    171 on at
  • MacNeg Profile Picture
    171 on at
    I also tried creating a simple class to run an sql select statement and did not get the same results vs when running the select statement in MS Azure data studio :( 
     
    Am I missing some flags, settings or attributes when using select statement in the code?  TIA.  
     
     
  • Martin Dráb Profile Picture
    239,660 Most Valuable Professional on at
    Your query is not cross-company; it'll try to load all records from the current company. You need to add crossCompany keyword to the select statement.
     
    As I mentioned, when debugging queries, it's useful to check what query you've got, not just what it returns.
     
    In select statements, you can do like this:
    select generateOnly forceLiterals purchTable
        where ...;
    
    info(purchTable.getSQLStatement());
     
  • MacNeg Profile Picture
    171 on at
    Thanks a lot Martin.  Still didn't work :(   I also added info to display SQL statement and I did not get any information.  Does it matter if my visual studio is the community 2022 version? 
     
    Thanks! 
     
  • Martin Dráb Profile Picture
    239,660 Most Valuable Professional on at
    Please share you latest code, so we can review it and run it. I doubt that you've found a bug in F&O; more likely there is a bug in your code, but identifying a bug in unknown code is difficult.
  • MacNeg Profile Picture
    171 on at
    Thanks Martin.  I have attached my newbie code to my previous post. For some weird reasons, it is not letting me post a reply - I tried it in Edge and Chrome. :(.   - This one just worked in Chrome - I am updating it to include my code... 
  • Martin Dráb Profile Picture
    239,660 Most Valuable Professional on at
    You missed a few important things in code that I shared:
    select generateOnly forceLiterals purchTable
        where ...;
    
    info(purchTable.getSQLStatement());
    In your code, you have neither generateOnly keyword (which is crucial) nor forceLiteral (which is optional, but useful), you're using a while select, which is useless when we just generate SQL statement and not actual fetch data from database. Also, don't bother trying to get SQL statement from salesTable. It's just a single query.
    while select crosscompany purchTable
        where purchTable.dataAreaId == "USMF"
           && purchTable.InterCompanyOrder == 1
        outer join salesTable
            where salesTable.SalesId == purchTable.InterCompanySalesId
               && salesTable.DataAreaId == purchTable.InterCompanyCompanyId
    {
    }
    
    info(strFmt("PurchTable SQL: %1", purchTable.getSQLStatement()));
    info(strFmt("SalesTable SQL: %1", salesTable.getSQLStatement()));
    It should look like this:
    select generateOnly forceLiterals crossCompany purchTable
        where purchTable.dataAreaId == "USMF"
           && purchTable.InterCompanyOrder == NoYes::Yes
        outer join salesTable
            where salesTable.SalesId == purchTable.InterCompanySalesId
               && salesTable.DataAreaId == purchTable.InterCompanyCompanyId;
    
    info(purchTable.getSQLStatement());
    By the way, I usually use Firefox, but I had to switch to Chrome for Dynamics Community, because quite a few things worked worse there. It's not ideal in Chrome either, but significantly better.

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 Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 671

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 621 Super User 2026 Season 1

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 589 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans