Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

formload from subgrid in UI

Posted on by 509

Has anybody had any issues with using formload with a subgrid?

I've a page which runs JavaScript based on a subgrid being updated, and it doesn't seem to be working since we've been forced to move to UI.

Thanks

Lee

  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: formload from subgrid in UI

    Hi partner,

    Yes, we should select "pass executionContext....." when we add it to events.

    I'm so glad that you've resolved your problem.

    If my answer helped you, please mark my answer as verified so that we choul help other users with similar issues.

    Best Regarsds,

    Leo

  • Lee-Martin Profile Picture
    Lee-Martin 509 on at
    RE: formload from subgrid in UI

    Got it, the execution context wasn't selected.

  • Lee-Martin Profile Picture
    Lee-Martin 509 on at
    RE: formload from subgrid in UI

    I've used F12 development - it's why I can see the console.log hasn't been activated.

    The code has been validated in an online validator and is validated correctly.

    The code is simply not being called.

  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: formload from subgrid in UI

    Hi partner,

    Yes, just add it to form "onload" event.

    If there is no outputting, please use F12 to open the development tools and check if there is any error message, you could also debug your code to check if the function triggered.

    If the code you provided above is the same in your event, then it miss a "}" at the last position.

    pastedimage1571217726287v2.png

    pastedimage1571217701534v1.png

    Hope it helps.

    Best Regards,

    Leo

  • Lee-Martin Profile Picture
    Lee-Martin 509 on at
    RE: formload from subgrid in UI

    Where do I call this function from?

    I've added it to my form's onload and it's not calling the function. My first line is a console log and it's not outputting.

    function subgridOnload(executionContext){

    console.log("in subgrid onload");

  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: formload from subgrid in UI

    Hi partner,

    Here's a doc for you.

    pastedimage1571216531965v1.png

    https://docs.microsoft.com/en-us/power-platform/important-changes-coming

    Hope it helps.

    Best Regards,

    Leo

  • Lee-Martin Profile Picture
    Lee-Martin 509 on at
    RE: formload from subgrid in UI

    "Xrm.page" is no longer supported in UI

    Ah thank you.

    Is there a list anywhere of everything that is no longer supported in UI?

    We keep finding these things, and we don't have the time or resource to hunt down everything that was working as required in the classic look before being forced onto UI.

  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: formload from subgrid in UI

    Hi partner,

    "Xrm.page" is no longer supported in UI, so please use "executionContext" instead like the code I provided above.

    Best Regards,

    Leo

  • Lee-Martin Profile Picture
    Lee-Martin 509 on at
    RE: formload from subgrid in UI

    The only thing  I've changed is the switch to Unified Interface. The code was working as expected in classic look.

    function formload() {

       var GridOnloadFunction = function() {

           SubgridModifed();

       };

       //Check if the grid is loaded and add the event handler to the subgrid.

       var checkgrid = window.setInterval(function() {

           if (Xrm.Page.getControl("DebitCards") != null) {

               Xrm.Page.getControl("DebitCards").addOnLoad(GridOnloadFunction);

               window.clearInterval(checkgrid);

           }

       }, 2000);

       var checkgridCredit = window.setInterval(function() {

           if (Xrm.Page.getControl("CreditCards") != null) {

               Xrm.Page.getControl("CreditCards").addOnLoad(GridOnloadFunction);

               window.clearInterval(checkgridCredit);

           }

       }, 2000);

    }

    function SubgridModifed() {

      firstFunction();

      secondFunction();

      thirdFunction();

      Xrm.Page.data.entity.save();

    }

  • Suggested answer
    LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: formload from subgrid in UI

    Hi partner,

    How did you add js functions to subgrid onload events?

    You could try the following code:

    Foe example I have an account subgrid on my form.

    function subgridOnload(executionContext){
        var formContext = executionContext.getFormContext();
        var gridContext = formContext.getControl("CustomGird");
        
        gridContext.addOnLoad(onloadFunction);
    }
    function onloadFunction () { 
        alert("Subgrid onload now!");
    };

    pastedimage1571191894968v2.png

    Note that you need to type in the correct subgrid name, not label.

    pastedimage1571191690173v1.png

    You could refer to this doc for more details.

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/grids/gridcontrol/addonload

    Hope it helps.

    Best Regards,

    Leo

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans