Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
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
     
     

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,900 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,275 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans