Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Answered

The SubGrid OnRecord Select event does not trigger when the grid is not editable.

Posted on by
Our requirement is to have a subgrid that recalculates the voucher price whenever a data item is selected, and it should also perform the recalculations for multiple selections. Is this something that Dynamics cannot do? From what I understand, we can only trigger the event when the grid is editable, which is not what we want. Is there any way to do this? 

  • Verified answer
    Dengliang Li Profile Picture
    Dengliang Li Microsoft Employee on at
    The SubGrid OnRecord Select event does not trigger when the grid is not editable.
    Hi,
     
    You can implement this through a custom rule for the subgrid button:
    Execute a specific method when a subgrid record is selected.
     
    In my example, when a Opportunity subgrid record is selected, the unbound action Recalculate is performed to recalculate the amount for that Opportunity.
     
    The code is below.
     
    async function main(SelectedItemIds){
        //If any subgrid records are selected.
        if(SelectedItemIds.length !==0){
            console.log(SelectedItemIds);
            //Iterate through all selected opportunity records and recalculate their amounts.
            for(let item of SelectedItemIds){
               await Recalculate(item).then(
                function success(response) {
                    if (response.ok) { console.log("Success"); }
                }
            ).catch(function (error) {
                console.log(error.message);
            });
            }
        }
       
        //Returns false and always hides the button.
        return false;
    }
     
    function Recalculate(ID){
     
        //Perform the unbound operation Recalculate.
        var execute_RecalculatePrice_Request = {
           
            entityLogicalName: "opportunity", // Edm.String
            entityId: {guid: ID }, // Edm.Guid
       
            getMetadata: function () {
                return {
                    boundParameter: null,
                    parameterTypes: {
                        entityLogicalName: { typeName: "Edm.String", structuralProperty: 1 },
                        entityId: { typeName: "Edm.Guid", structuralProperty: 1 }
                    },
                    operationType: 0, operationName: "RecalculatePrice"
                };
            }
        };
       
        return Xrm.WebApi.execute(execute_RecalculatePrice_Request)
    }
     
     
    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more.
    If you have further questions, please feel free to contact me .
     
    Best Regards,
    Dengliang Li
     
     

Helpful resources

Quick Links

Can you answer this forum question?

You could make someone's day!

Community Newsletter - May 2024

Kudos to our community stars!

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,632 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 224,528 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans