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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Obtain selected records from a form (multiselect)

(0) ShareShare
ReportReport
Posted on by 329
I have created an extension in the validateWrite method of the EssLeaveRequestEntry form
(executed when you click on 'update time off' in the action bar @ {D365BaseUrl}/?cmp={company}&mi=HcmEmployeeSelfServiceWorkspace)
 
What I am doing is selecting 2 records, then clicking update time off. Then a window opens and I change the date via the datepicker to a new date.
 
Now when I click submit, I enter my validateWrite extension and here I want to execute some logic, for the records I selected on the base form.
 
When only 1 record is selected, I can obtain it with:
*LeaveRequestCalendar requestToEdit = element.args().record();
 
However I cannot get it to work to select multiple records. I tried the following 3 solutions I found:
 
SOLUTION 1:
            MultiSelectionContext selectionContext;
            selectionContext = element.args().multiSelectionContext();
            LeaveRequestCalendar leaveRequestOld;
            if (selectionContext && selectionContext.getFirst())
            {
                while(selectionContext)
                {
                    daysList.addEnd(leaveRequestOld.LeaveDate);
                    leaveRequestOld = selectionContext.getNext();
                }
                daysList.empty();
            }
 
Problem: This solution gives me a timeout without ever getting through the logic
 
SOLUTION 2:
           FormDataSource requestFds = element.args().record().dataSource();
           LeaveRequestCalendar leaveRequestOld2 = requestFds.getFirst();
           while(leaveRequestOld2)
           {
               daysList.addEnd(leaveRequestOld2.LeaveDate);
               leaveRequestOld2 = requestFds.getNext();
           }
           daysList.empty();
 
Problem: This solution gives me ALL the records of the datasource, not just the selected ones
 
SOLUTION 3:
           MultiSelectionHelper helper;
           helper  = MultiSelectionHelper::createFromCaller(element.args().caller());
           LeaveRequestCalendar leaveRequestOld3 = helper.getFirst();
           while(leaveRequestOld3)
           {
               daysList.addEnd(leaveRequestOld3.LeaveDate);
               leaveRequestOld3 = helper.getNext();
           }
           daysList.empty();
 
Problem: This solution also gives me ALL the records of the datasource, not just the selected ones
 
I probably am missing something in my code, but I would not know what. Could someone tell me how I can get the wanted functionality?
I have the same question (0)
  • Verified answer
    Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    Hi SuperBunny,

    In general, here's how you can use the "MultiSelectionHelper" class

    let's say you selected multiple records then clicked a button. On the clicked method of the button, you can write sth like this:
                    MultiSelectionHelper        multiSelectionHelper    = MultiSelectionHelper::construct();
                    multiSelectionHelper.parmDatasource(Table1_ds);
                    Table1 table1 = multiSelectionHelper.getFirst();
        
                    while(table1)
                    {
                        //logic
        
                        table1 = multiSelectionHelper.getNext();
                    }
    It seems you don't want to loop through records when you first click the 1st button right? so maybe you need to pass table1 in my example to the 2nd button somehow and loop there, or get the caller datasource. If you want more details, then please show us your full code.
    Try testing the code first on the first button make sure it gets you the required result, then see what you need to do next

    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at
    Using MultiSelectionContext is a good approach. Let's try it in more steps, which will make it easier to debug:
    LeaveRequestCalendar callerRecord = element.args().record();
    
    if (!callerRecord)
    {
        throw error("No caller record");
    }
    
    FormDataSource callerDs = FormDataUtil::getFormDataSource(callerRecord);
    
    if (!callerDs)
    {
        throw error("No caller data source");
    }
    
    MultiSelectionHelper selectionHelper = new MultiSelectionHelper();
    multiSelectionHelper.parmDatasource(callerDs);
    
    LeaveRequestCalendar leaveReqCal = selectionHelper.getFirst();
    
    while (leaveReqCal)
    {
        daysList.addEnd(leaveReqCal.LeaveDate);
        leaveReqCal = selectionHelper.getNext();
    }
    Also, how are you selecting the records?
     
    Will similar code works if you call it directly from HcmEmployeeSelfServiceWorkspace? (There you wouldn't refer to a caller, of course.)
  • Superbunny Profile Picture
    329 on at
    Thank you both.
     
    I solved it now and, as more or less mentioned by both of you, the missing line was:
     
     selectionHelper.parmDatasource(callerDs);
     
    Creating the selectionHelper from the caller alone was not enough and I really had to set the datasource. 
    I'll give the answer to the first responder, but will like both the responses!
     
    Thanks again!
  • Hana Xue Profile Picture
    Microsoft Employee on at
    Hi,
    If the issue is resolved, please mark this as verified to help more people on the forum. Thanks in advance.
    Best Regards,
    Hana
  • Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    Hi SuperBunny,
     
    You mentioned that you want to give the answer to the first responder.
     
    Please go to that answer and click on the the tick box that says "Does this answer your question"
     
    Thanks,
    Layan Jweihan
  • Superbunny Profile Picture
    329 on at
    Hey guys,
     
    I will do that and I've been trying that but each time I click the checkbox, the page keeps on loading without end :o
     
    Will keep trying though! :)
  • Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    I will verify the answer on behalf of you

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans