Skip to main content

Notifications

Announcements

No record found.

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

Multiple ranges on form init method

(0) ShareShare
ReportReport
Posted on by 576

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));
}

  • D365  beginner Profile Picture
    D365 beginner 576 on at
    RE: Multiple ranges on form init method

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

  • Verified answer
    ergun sahin Profile Picture
    ergun sahin 8,812 Super User 2024 Season 1 on at
    RE: Multiple ranges on form init method

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

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Multiple ranges on form init method

    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")));

  • D365  beginner Profile Picture
    D365 beginner 576 on at
    RE: Multiple ranges on form init method

    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.

  • Suggested answer
    ergun sahin Profile Picture
    ergun sahin 8,812 Super User 2024 Season 1 on at
    RE: Multiple ranges on form init method

    You can use expressions in query ranges

    www.axaptapedia.com/Expressions_in_query_ranges

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans