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 :
Finance | Project Operations, Human Resources, ...
Answered

CurrentUserId() method as the range in the static query ( AOT query)

(0) ShareShare
ReportReport
Posted on by 223

Hi Friends,

 I am trying to give the CurrentUserId() method from SysQueryRangeUtil class as the range in the static query (AOT query) to filter the record related to the currnent user. 

The value is not getting filtered. if I hard-code the current user id as "abcuser" in the range it works fine

Note: we cannot use the metnod "curUserId()". we need to use method from the class SysQueryRangeUtil.

Have you come across this kind of issue?

your help much appreciated.

Regards

Martin 

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

    How did you try to use it? Do you know that the value must be (currentUserId()) and not just currentUserId()?

  • martinarul Profile Picture
    223 on at

    Hi Martin,

    I gave the range value as you suggested only. I gave within the brackets but it did not work as well.

    I tried the following ways:

    (CurrentUserId())

    SysQueryRangeUtil::CurrentUserId()

    (SysqueryRangeUtil::CurrnetUserId())

    none of it seem to work.

    Regards

    Martin

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Martin,

    Martin Dráb is right, (currentUserId()) is the correct statement. I can confirm that it works. How did you decide that it doesn't work? Maybe you expect another behavior?

  • Blue Wang Profile Picture
    on at

    HI Martin Arul,

    The SysQueryRangeUtil class includes a number of functions that list pages used  to dynamically control the data that is shown based on the value that id returned by the function.

    As mentioned, The function call has to use the same syntax  as passing expressions in a range value.the whole value needs to be surrounded by an opening "(" and closing ")".

    Please refer : community.dynamics.com/.../using-dynamic-query-values-sysqueryrangeutil-in-dynamics-ax-115157664

    Put class method directly in datasource range node as (SysQueryRangeUtil::currentUserId()).

  • martinarul Profile Picture
    223 on at

    Hi Sergei,

    I am using dynamics 365 F&O (Update31), I had put the range as Martin suggested only but, it does not filter the record based on the current user ID.

    Regards

    Martin. A

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Martin,

    How do you run operation (batch or not)?

  • martinarul Profile Picture
    223 on at

    Hi Sergi,

    Basically I wanted to create a static query to be applied in the security policy for XDS purpose and wanted to filter the data based on the current user who logged-in. when I attached that query in a View and opened in the table browser, it did not filter the record. if I give one user value as a string (e.g: "abcUser") then it works fine, but if I give as (CurrentUserId()) it is not filtering the record.

    For testing purpose i created a simple view and added "purchTable" as datasource and and added "createdBy" field as range and gave the range value as "(currentUserid()), it did not filter the data for me.

    pastedimage1584089608493v1.png

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Martin,

    But it's not a query object. I'm not sure if it's working for views as views are physically created in DB as real SQL views.

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

    This can't work. The method will be executed just once, on synchronization, and this single user ID will be included in the view definition.

    If you need a view, let it return a column with user IDs and filter this column in a query.

  • martinarul Profile Picture
    223 on at

    Hi Martin,

    As you mentioned, my query was combined with tables and views, unfortunately my range was in the view and so it took only one userID during the synchronization.

    Regards

    Martin

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans