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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Add Range in AOT Query where worker is not logged in person

(0) ShareShare
ReportReport
Posted on by

Hi,

I have HcmWorker as datasource in my AOT Query and i want to restrict the resultset by not having logged in person in the output. Here please consider that all ax users have corresponding worker related to it. 

If i want to include current user i would use   (currentWorker()) in the value field of the Range. but I'm not sure how to exclude current worker.  I tried !(currentWorker()) but it doesn't work. Any hint would be helpful.

*This post is locked for comments

I have the same question (0)
  • AX 2012 r3 Profile Picture
    2,426 on at

    Hi VDY,

    Are you using AOT Query or is it Query using X++

    Regards.

  • Community Member Profile Picture
    on at

    It's AOT query. I believe I mentioned that in my question.

    I could put the range in the  executeQuery() method of the datasource after adding this AOT query to the Form.

    but just want to know if it's possible to exclude logged in worker at design time.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    It is somewhat unclear on what you mean by logged in worker.

    But if you mean Online users form, the table behind is called SysClientSessions. If you want to start from HCMWorker, then you need to join that with UserInfo, after which you can link it to SysClientSessions based on Id (which is UserId).

    That way you can filter your workers by putting a range on the SysClientSessions.Status field.

  • Community Member Profile Picture
    on at

    Hi Vilmos,

    You are correct that i want to filter based on current user id.  but i want to exclude them from the output. Is that possible to exclude without adding UserInfo table in the join.

  • Adam Duckworth Profile Picture
    130 on at

    Its not as simple as !(curUserId()) is it?

  • Community Member Profile Picture
    on at

    that's why my query.

  • Suggested answer
    Martin Dráb Profile Picture
    239,735 Most Valuable Professional on at

    I gave it a try and it seems that "it doesn't work" in this case means that when trying to put such a range value, AX immediately shows this error: Invalid value (!(currentWorker())) specified in the query predicate.

    I would simply create a new method (such as notCurrentWorker() in SysQueryRangeUtil - then you can use it in the same way as currentWorker().

    It can be as simple as this:

    public static str notCurrentWorker()
    {
        return strFmt('!%1', DirPersonUser::currentWorker());
    }
  • Community Member Profile Picture
    on at

    Hi Martin,

    Thanks for guiding to right direction.

    I tried it. but as my Range is on RecId field of HcmWorker, it doesn't accept string value returned from notCurrentWorker() method.

    I throws below error.

    "Query extended range failure: Syntax error near 0."

    I think I should go with the executeQuery method filter.

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

    Of course it does accept strings. The range value is a string, regardless of the type of your field. If you provide a number, is converted to string before setting as a range value. Also, I tested it before sending my reply.

    You either have a bug in the method, or you're using it wrong.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 16

#2
Nagendra Varma K Profile Picture

Nagendra Varma K 4

#2
Harisgillani Profile Picture

Harisgillani 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans