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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

CrossCompany select doesn't return data to non-admin users

(0) ShareShare
ReportReport
Posted on by 895

Hi,

I am using AX 2012 R3 CU11.

I have a scenario where in need to write the below logic,

while select * from payrollPayPeriod where payrollPayPeriod.PeriodEndDate == selectedEndDate // Global Table
{
while select crossCompany * from payrollEarningStatement where payrollEarningStatement.PayPeriod == payrollPayPeriod.RecId // Not a Global Table
{
while select crossCompany * from payrollEarningStatementLine where payrollEarningStatementLine.EarningStatement == payrollEarningStatement.RecId // Not a Global Table
{

while select * from payrollEarningCode where payrollEarningCode.RecId == payrollEarningStatementLine.EarningCode // // Global Table

.

.

.

I have 3 legal entities - A, B, C. I have few discrepancies in legal entity B which this execution of class gives as the output. 

I have written this logic in a dialog and when I am running this dialog from AOT, it gets the required result irrespective of my logged-in company (i.e. be it any A or B or C )

Now I have created a separate security role for this dialog class is attached.

Now I am facing the weird issue as detailed below,

Scenario-1: Code is as detailed above above with CrossCompany keyword.

(a) When I run AX with user X = "System Admin Role" Assigned, Logged-in company - A or B or C,

When I run this class from AX client, I got the correct desired result with the records from Company B.

(b) When I run AX with user Y = "No system Admin Role" assigned, logged-in company - A or B or C,

When I run this class from AX client, it returns no result (This is wrong). I was expecting the same result as in Scenario-1 (a).

Scenario-2: Code is as detailed above above without CrossCompany keyword.

(a) When I run AX with user X = "System Admin Role" Assigned, Logged-in company - B,

When I run this class from AX client, I got the correct desired result with the records from Company B.

(b) When I run AX with user X = "System Admin Role" Assigned, Logged-in company - A or C

When I run this class from AX client, it returns no result (As Expected)

(c) When I run AX with user Y = "No system Admin Role" assigned, logged-in company - B,

When I run this class from AX client, I got the correct desired result with the records from Company B.

(d) When I run AX with user Y = "No system Admin Role" assigned, logged-in company - A or C

When I run this class from AX client, it returns no result (As Expected)

Scenario-2 is just for your reference. I am interested for scenario-1 wherein I  will be assigning this functionality to the users not having admin rights but having access to all the legal entities.

I am not sure where I am missing what which is causing this issue?

Can someone please help me resolve this issue as it seems to be a very minor issue.

Thanks in advance.

Sincerely,

Muneeb

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    239,392 Most Valuable Professional on at

    What about debugging your code to which of your four statements returns no data?

    You're in a much better position to solve your problem than we're, because we don't have your data nor know your exact security setup and we can't debug the code.

    By the way, I hope you have nested while selects just for testing; it's way too inefficient to be used for real implementations.

  • Muneeb Profile Picture
    895 on at

    Yes, you are absolutely right regarding nested while loops.

    The code is not getting inside second while loop.

    Debugging when admin role is there along with the new role as above, everything is working as expected.  (As detailed above)

    The issue comes up the moment I am assigning the user this new role along with some other standard role i.e. Accountant (No Admin role in this case).

    Sincerely,

    Muneeb

  • Martin Dráb Profile Picture
    239,392 Most Valuable Professional on at

    If I understand it correctly, you're saying that you have a problem with this statement not returning any record:

    select crossCompany * from payrollEarningStatement
    where payrollEarningStatement.PayPeriod == {someID}

    and we can ignore all the remaining code.

    Your description above suggests that you have a record in company B with PayPeriod equal to the given ID, but it's not returned when running with certain restricted permissions ("No system Admin role"), even if you run it in company B (and it works if you merely remove the crossCompany keyword, without making any other change). Is that correct?

  • Muneeb Profile Picture
    895 on at

    Yes, you are right.

    If I am logged-in by a user not having System Admin rights assigned and inside company B,

    (a) I am getting the records from company B, if I remove crosscompany keyword.

    (b) I am NOT getting any records from company B, if I keep this crosscompany keyword.

    This behavior is from the AX Client after making the code changes in (a) & (b).

    Sincerely,

    Muneeb

  • Verified answer
    Martin Dráb Profile Picture
    239,392 Most Valuable Professional on at

    Does the user have access to the table in all companies?

    I think the best next step is observing the actual SQL query sent to database. If there is any, it might be immediately obvious what's wrong with it, or you can execute it directly against the database and make your testing much easier by removing several extra layers of complexity.

  • Muneeb Profile Picture
    895 on at

    I have executed the query directly against SQL and below are the details,

    (For First WHILE LOOP) - select RecId from payrollPayPeriod where PERIODENDDATE = '4/30/2017'

    Result is below:

    --------------------------------------------------------

    RecId

    5637147746 (For this)

    5637147591

    5637147650

    5637147614

    5637147674

    5637147662

    5637147698

    5637147686

    5637147710

    5637147722

    5637147734

    5637147770

    5637147758

    --------------------------------------------------------

    (For Second while LOOP) - select RecId from payrollEarningStatement where PAYPERIOD = '5637147746'

    Result is below:

    -----------------------------------------------------

    RecId

    5637214417
    5637214419
    5637214421
    5637214422
    5637214424
    5637214425
    5637214426
    5637214427
    5637214428
    5637214429
    5637214430
    5637214431
    5637214433
    5637214434
    5637214436
    5637214438
    5637214439
    5637214440
    5637214441
    5637214442
    5637214443
    5637214444
    5637214445
    5637214446
    5637214456
    5637214457
    5637214458
    5637214459
    5637215126

    --------------------------------------------------------

    Likewise we do have multiple records present in the payrollEarningStatement table for each recId of payrollPayPeriod as detailed above.

    Sincerely,

    Muneeb

  • Martin Dráb Profile Picture
    239,392 Most Valuable Professional on at

    So what's the SQL query in the case that doesn't work? The list of record IDs has a no value for us, but if you shared the query, we could help you stop a problem in it.

  • Muneeb Profile Picture
    895 on at

    I am sorry for the delay in update as I was looking into some other critical issue that popped up.

    You were right, the issue was with the Access of the tables to involved in the code. After providing the access of the tables involved to the newly created privilege, the code was working fine.

    Appreciate and thank you so much for your help.

    Sincerely,

    Muneeb

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans