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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Get the Current Active Company RecId in Dynamics AX.

(0) ShareShare
ReportReport
Posted on by 125

Any body tell me how to get the Current Active Company RecId in Dynamics AX 2012.

I want to set range in query data source on the base of RecId,but dont know how to do.

08021.Capture.PNG

In the value field,i want to pass current active company RecId.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    udaY-ch Profile Picture
    5,133 on at

    Hi,

    You need to set the range in the init method of the query.

    public void init()

    {

    LegalEntity legalEntity = CompanyInfo::find().RecId;

    super();

    this.query().dataSourceTable(tablenum(Yourtable)).findRange(fieldnum(YourTable,LegalEntity)).value(queryValue(legalEntity));

    }

    /Uday.

  • Verified answer
    Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    You can't use curExt(), because normal X++ methods can't be used as query range values and it doesn't even return RecId.

    But there is a solution - you can use methods from SysQueryRangeUtil class, you just have to wrap them in extra brackets. Therefore instead of curExt(), you could use (currentCompany()).

    This still doesn't return RecId, but you can create a new method (e.g. currentCompanyRecId()) doing what you need.

  • Faran Baig Profile Picture
    125 on at

    Martin ! Actually i want to restrict workers to company specific on Retail worker forms.Want to show the workers belonging  to current legal entity only.As you can see in below attached screenshot,All workers are showing in case of USRT company,but i want only workers to be shown that belongs to USRT.

     

    0576.Capture.PNG

  • Faran Baig Profile Picture
    125 on at

    Udhaya Just i need this in init method of query,no need of execute query method or any other?

  • udaY-ch Profile Picture
    5,133 on at

    Yes. This would solve your issue.

  • Faran Baig Profile Picture
    125 on at

    Udhaya i have used same query coming under Form HcmWorkerListPage Data Sources named as HcmWorkerListPage and added above method in init method,

    but not getting desirable results.Means by logging from other user and assigning my role,it is still showing all workers in Retail>Workers  in any company. Although i have removed System Administrative role.

  • udaY-ch Profile Picture
    5,133 on at

    Try to clear the AUC files and clear usage data and try checking the same. It should work.

  • Faran Baig Profile Picture
    125 on at

    Udhaya Facing an issue in line 5,query worked,but this time nothing is showing,may be due to this stack trace.

    76202.Capture.PNG

  • Verified answer
    udaY-ch Profile Picture
    5,133 on at

    HI,

    You need to create a range. Take a look at the query KanbanMultiKanbanReceive

    /Uday.

  • Faran Baig Profile Picture
    125 on at

    Udhaya my role is working fine,but a single problem is that,query takes the RecId of first company when ax opens up first time,and showing correct data of that company,but when i changes the company,it is still showing the data filtered on the basis of previous company RecId,now how to refresh and pass the next company RecId(if i change company)?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans