Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

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

Posted on 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
    martinarul 217 on at
    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
    Martin Dráb 230,235 Most Valuable Professional on at
    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
    Sergei Minozhenko 23,089 on at
    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
    martinarul 217 on at
    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
    Sergei Minozhenko 23,089 on at
    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
    martinarul 217 on at
    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
    Blue Wang on at
    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
    Sergei Minozhenko 23,089 on at
    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
    martinarul 217 on at
    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
    Martin Dráb 230,235 Most Valuable Professional on at
    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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans