Skip to main content
Post a question

Notifications

Community site session details

Community site session details

Session Id : TQurd+IyVJz0O6qga9aZGt
Finance | Project Operations, Human Resources, ...
Answered

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

Like (0) ShareShare
ReportReport
Posted on 12 Mar 2020 11:08:58 by 217

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 

  • martinarul Profile Picture
    217 on 13 Mar 2020 at 12:50:52
    RE: CurrentUserId() method as the range in the static query ( AOT query)

    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

  • Verified answer
    Martin Dráb Profile Picture
    232,195 Most Valuable Professional on 13 Mar 2020 at 10:19:46
    RE: CurrentUserId() method as the range in the static query ( AOT query)

    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.

  • Sergei Minozhenko Profile Picture
    23,091 on 13 Mar 2020 at 09:24:44
    RE: CurrentUserId() method as the range in the static query ( AOT query)

    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.

  • martinarul Profile Picture
    217 on 13 Mar 2020 at 08:54:13
    RE: CurrentUserId() method as the range in the static query ( AOT query)

    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,091 on 13 Mar 2020 at 06:47:13
    RE: CurrentUserId() method as the range in the static query ( AOT query)

    Hi Martin,

    How do you run operation (batch or not)?

  • martinarul Profile Picture
    217 on 13 Mar 2020 at 06:09:57
    RE: CurrentUserId() method as the range in the static query ( AOT query)

    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

  • Blue Wang Profile Picture
    on 13 Mar 2020 at 02:38:19
    RE: CurrentUserId() method as the range in the static query ( AOT query)

    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()).

  • Sergei Minozhenko Profile Picture
    23,091 on 12 Mar 2020 at 18:00:38
    RE: CurrentUserId() method as the range in the static query ( AOT query)

    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?

  • martinarul Profile Picture
    217 on 12 Mar 2020 at 11:58:52
    RE: CurrentUserId() method as the range in the static query ( AOT query)

    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

  • Martin Dráb Profile Picture
    232,195 Most Valuable Professional on 12 Mar 2020 at 11:28:05
    RE: CurrentUserId() method as the range in the static query ( AOT query)

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

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,323 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,195 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans
Loading started
Loading complete