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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Multiple ranges on form init method

(0) ShareShare
ReportReport
Posted on by 636

Hi Experts,

I have a customized form where I have created a range in the init method of the form to enable users to see only the records where the user's personnel number matches with the employee Id field in the table. below is the code that I have added and its works fine. Now I need to add one more range that there is a field named USERID in the table and match it with curUserId(). So the user will be able to view the records created by him and where ever his employee id is mentioned by some other user also. I hope the requirement is clear how Can I add it in the below code ?

public void init()
{
RecId EmployeeId;
HcmWorker _hcmWorker;

super();

EmployeeId = DirPersonUser::findUserWorkerReference();

select _hcmWorker where _hcmWorker.RecId == EmployeeId;

MyTable_Ds.query().dataSourceTable(Tablenum( MyTable)).addRange(fieldNum( MyTable,EmployeeId)).
value(SysQuery::value(_hcmWorker.PersonnelNumber));
}

I have the same question (0)
  • Suggested answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    You can use expressions in query ranges

    www.axaptapedia.com/Expressions_in_query_ranges

  • D365  beginner Profile Picture
    636 on at

    Hi Ergun,

    Thanks for your response. In my case I need to add ranges in two fields with OR condition.

    MyTable.Employee Id with User Personnel number

    MyTable.User Id  with Current user

    Is this can be done using expressions ? Can you please help me to rewrite the above code.

  • Verified answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    Hi, yes it can be achieved by using Expressions in query ranges.

    There's an example in the page that matches your requirement exactly (having OR range for two different fields).

    This is the example - understanding it and applying the understanding to your requirement is your homework  

    Find records where the ItemType is Service or the ItemId is B-R14. Note the nesting of the parenthesis in this example.

    queryBuildRange.value(strFmt('((ItemType == %1) || (ItemId == "%2"))', 
        any2int(ItemType::Service),
        queryValue("B-R14")));

  • Verified answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    Yeap, You can do. Look for this lines

    queryBuildRange.value(strFmt('((ItemType == %1) || (ItemId == "%2"))', 
        any2int(ItemType::Service),
        queryValue("B-R14")));

    in your case something like this;

    queryBuildRange.value(strFmt('((EmployeeId == %1) || (UserId == "%2"))', 
        queryValue(_hcmWorker.PersonnelNumber),
        queryValue(curUserId())));

  • D365  beginner Profile Picture
    636 on at

    Thanks for your support Ergun & Nikolaos. Its worked fine.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 694

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 646 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 337

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans