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

How to deal with multiselecthelper on clicked event ?

(0) ShareShare
ReportReport
Posted on by 207

Hey friends,

I'm looking for some help.

I got Two forms A and B.

On form A i got some grid with raws and it values.

I want to select one or more raws and when i click on form A button i will reach form B.

This form B need to be feed by the raws i selected before on form A.

I tried this code :

 [FormControlEventHandler(formControlStr(EUKShowDetailsItemsForm, EUKLevelModifier), FormControlEventType::Clicked)]
    public static void EUKLevelModifier_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        Args args = new Args();
        FormRun formRun, callerFormRun;
        //EUKSecurityTreeNode EukSecurityTreeNode;

        FormDataSource    EUKShowDetailsItemsForm_DS = sender.formRun().dataSource(formDataSourceStr(EUKShowDetailsItemsForm, EUKSelectedMenus));

        MultiSelectionHelper    selectionHelper = MultiSelectionHelper::construct();
        EUKSelectedMenus    eukSelectedMenus;


        selectionHelper.parmDataSource(EUKShowDetailsItemsForm_DS);


        
        args.name(formstr(EUKModifyMenuItemsAccessLevel)); // Assign to args form parameters
        
        formRun = classfactory.formRunClass(args);

        eukSelectedMenus  = selectionHelper.getFirst();

        if (eukSelectedMenus.RecId)
        {
            while (eukSelectedMenus.RecId != 0)
            {
                eukSelectedMenus = selectionHelper.getNext();
            }
        }
        //eukSelectedMenus = sender.formRun().dataSource().cursor(); //Get row values from row selected
        args.record(eukSelectedMenus); //Assign to args values
        formRun.init();
        formRun.run();
        formRun.detach();
    }

The loop worked but args didnt register raws values.

Thanksfully.

  • Awaxx Profile Picture
    207 on at
    RE: How to deal with multiselecthelper on clicked event ?

    A

  • Awaxx Profile Picture
    207 on at
    RE: How to deal with multiselecthelper on clicked event ?

     goshoom 

    Wowww it's seem so easy for you that's incredible.

    I hope to learn skills like yours but unfortunately i was trained only on basis and i got to learn all the rest by myself.

    But i'm glad this forum exist and people like you ready to take care and share time with noobs like me.

  • Verified answer
    Martin Dráb Profile Picture
    231,772 Most Valuable Professional on at
    RE: How to deal with multiselecthelper on clicked event ?

    Again, please throw away the whole EUKLevelModifier_OnClicked(). You wrote code that it's not needed at all and it's actually worse than what the system does for you automatically.

    Now let's look at your code in executeQuery().

    I see you're ignoring the query that the form created for your data source and you're creating a new query instead. It's not necessary and it even has some problems. Instead, simply modify the existing query. This is how you can get the QueryBuildDataSource object:

    QueryBuildDataSource treeNodeQbds = EukSecurityTreeNode_ds.queryBuildDataSource();

    You already seem know how to use MultiSelectionHelper, and I showed you how to initialize from the caller data source, therefore you should already been able to iterate records.

    Another problem in your code is using the extended query syntax (things like ((%1 == "%3") && (%2 == "%4"))), which you shouldn't use unless necessary, and it's not necessary in this case. Simply add two ranges:

    treeNodeQbds.addRange(fieldNum(EukSecurityTreeNode, SecurableName).value(...);
    treeNodeQbds.addRange(fieldNum(EukSecurityTreeNode, MatrixRole).value(queryValue()).value(...);

    If we put it together, it'll look somehow like this:

    QueryBuildDataSource treeNodeQbds = EukSecurityTreeNode_ds.queryBuildDataSource();
    FormDataSource callerDataSource = FormDataUtil::getFormDataSource(element.args().record());
    
    if (callerDataSource)
    {
    	MultiSelectionHelper selectionHelper = MultiSelectionHelper::construct();
    	selectionHelper.parmDataSource(callerDataSource);
    	
    	eukSelectedMenus = selectionHelper.getFirst();
    	
    	while (eukSelectedMenus)
    	{
    		treeNodeQbds.addRange(fieldNum(EukSecurityTreeNode, SecurableName)
    			.value(queryValue(eukSelectedMenus.SecurableName));
    		treeNodeQbds.addRange(fieldNum(EukSecurityTreeNode, MatrixRole).value(queryValue())
    			.value(queryValue(eukSelectedMenus.EUKMatrixId));
    	
    		eukSelectedMenus = selectionHelper.getNext();
    	}
    }

    But doing this in executeQuery() would be a bug, because you would add ranges every time when the query gets re-executed. If you insist on doing it in executeQuery(), remove all the ranges at the beginning.

  • Awaxx Profile Picture
    207 on at
    RE: How to deal with multiselecthelper on clicked event ?

    pastedimage1645695995711v1.png here is my form A

    There i was first working on selecting a row to get it with other values on form B

    So i wrote that : 

     [FormControlEventHandler(formControlStr(EUKShowDetailsItemsForm, EUKLevelModifier), FormControlEventType::Clicked)]
        public static void EUKLevelModifier_OnClicked(FormControl sender, FormControlEventArgs e)
        {
            Args args = new Args();
            FormRun formRun, callerFormRun;
            EUKSelectedMenus    eukSelectedMenus;
            EUKSecurityTreeNode EukSecurityTreeNode;
            
            args.name(formstr(EUKModifyMenuItemsAccessLevel)); // Assign to args form parameters
            
            formRun = classfactory.formRunClass(args);
            eukSelectedMenus = sender.formRun().dataSource().cursor(); //Get row values from row selected
            args.record(eukSelectedMenus); //Assign to args  values
            formRun.init();
            formRun.run();
            formRun.detach();
        }

    With that code i was able to get record for one row and reach form B.

    I create a query on form B 

            public void executeQuery()
            {
                // Mack - 22/02 - New Query to filter from Show details rows selected and matrix Id
    
                EUKSelectedMenus        selectedMenus;
                QueryRun            qr;
                Query q;
                QueryBuildDataSource qbd;
                QueryBuildRange qbr;
                str rangestr;
    
                selectedMenus = element.args().record();
    
                str secuName = selectedMenus.SecurableName;
                str secuMtrxId = selectedMenus.EUKMatrixId;
    
                // Query and range creation
                q = new Query();
    
                qbd = q.addDataSource(TableNum(EukSecurityTreeNode));
    
                rangeStr = strFmt('((%1 == "%3") && (%2 == "%4"))',
                           fieldStr(EukSecurityTreeNode, SecurableName),
                           fieldStr(EukSecurityTreeNode, MatrixRole),
                           secuName,
                           secuMtrxId);
    
    
                qbr = qbd.addRange(fieldNum(EukSecurityTreeNode, MatrixRole));
                qbr.value(rangeStr);
    
    
    
                //Query application on datasource
                EukSecurityTreeNode_ds.query(q);
    
    
    
                super();
    
    
    
    
            }

    There i was able to get this form B with filter in action : 

    pastedimage1645696240412v2.png

    But now i must change this behaviour and i must be able to select multiple rows and get it on form B with the same filtering result

    Thank you for your time goshoom 

  • Martin Dráb Profile Picture
    231,772 Most Valuable Professional on at
    RE: How to deal with multiselecthelper on clicked event ?

    A grid is based on data sources, and a data sources gets data from a query, which loads some data from a table. Therefore you should focus on what database query you want to create.

    Saying things like "from form A == to form B" isn't really helpful, because it says little about which data you want to fetch from database.

  • Awaxx Profile Picture
    207 on at
    RE: How to deal with multiselecthelper on clicked event ?

    Hi goshoom 

    There is similar fields like "matrix id" and "label name".

    So what i want to do is to feed other fields where "matrix id" and "label name" from form A == to form B

  • Martin Dráb Profile Picture
    231,772 Most Valuable Professional on at
    RE: How to deal with multiselecthelper on clicked event ?

    Can you elobrate it, please?

    You have an ID. What you will do with it? Do you want to find records in the table used for the data source in Form B that has the same value in a certain field?

  • Awaxx Profile Picture
    207 on at
    RE: How to deal with multiselecthelper on clicked event ?

    goshoom 

    What i wanna do is simple.

    I will first select row from form A and that rows will contain some values

    That values like "id" will be compare to form B which it feed by another datasource and that comparison will give me other values to display on form B.

  • Verified answer
    Martin Dráb Profile Picture
    231,772 Most Valuable Professional on at
    RE: How to deal with multiselecthelper on clicked event ?

    If you want to filter data in form A, change the query in form A. If you want to filter data in form B, change the query in form B.

    executeQuery() gets called every time when you refresh the form and I'm not really sure that it's the right place. It all depends on what exactly you want to do.

  • Awaxx Profile Picture
    207 on at
    RE: How to deal with multiselecthelper on clicked event ?

    Hey goshoom ,

    If i choose your way and i want to filter with a query, how could i do it ?

    Imagine i overide the init method on EUKShowDetailsForm (Form A) and i grab my multiselection values.

    This selection will give me some values that i need to make some comparison on form B to feed it with the good field values.

    The query should be overiden on this form B as "Execute Query" method or on form A ?

    I m a bit lost honestly.

    Thanksfully.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,892 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,772 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans