Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Update field after value update

Posted on by 15

Hello all, please consider this scenario:

I have two entities, and B with a N:N relationship between them.

On form I have a read-only subgrid where the user can add/remove B records, triggering a plugin on server side for the associate/disassociate event.

This plugin reads the Value field from all the records currently associated with A and sums it, updating the read-only field TotalValue from A present on the same form the user is making the changes.

My issue is that the change is not being reflected to the form, where the TotalValue shows the old value until the user refreshes the page. 

On the client side I have an onLoad event for the subgrid that calls a script, where I'm trying to read the Value from all the entities and update the TotalValue field on the form, but since my subgrid is read-only I can't call getAttribute on it to read this value.

I know I have some options, but I have a down side for them, like:

Forcing form refresh with formContext.data.refresh() - I don't want to save/ignore the changes of the whole form all the time the user makes a change on the subgrid (I'm also not using auto save)

Fetch the values with Xrm.WebApi.retrieveMultipleRecords() - This sounds like my last reasonable option, but since the B entities were already loaded to the grid and the Value is being shown on the grid, I can't stop thinking that must be a easier way to do that.

 

Any ideas to this scenario that I am missing?

Thanks.

  • Radu Chiribelea Profile Picture
    Radu Chiribelea 6,667 on at
    RE: Update field after value update

    Hi Cassio,

    Yes, that is correct.

    Make sure you don't submit the value when saving the form (in case somebody else overwrites it in the mean time)

    Regards,

    Radu

  • cmilanelo Profile Picture
    cmilanelo 15 on at
    RE: Update field after value update

    Hi Redu,

    So your suggestion is retrieving the TotalValue from the target entity and then set it to the field, instead of retrieving multiple from the related entities and repeat the operation, is that right?

    Well, it sounds like a good solution.

    Thank you for your input!

  • Verified answer
    Radu Chiribelea Profile Picture
    Radu Chiribelea 6,667 on at
    RE: Update field after value update

    Hi Cassio,

    I would look at following option. Have a JS triggered onLoad of the Grid (the grid will refresh each time you associated a new record B with record A) and retrieve https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-webapi/retrieverecord  the TotalValue from record A from the CRM Platform (which should have the latest value calculated by the plugin triggered on the associate event)

    See following : docs.microsoft.com/.../subgrid-onload

    Also, i wouldn't suggest refreshing the form on onLoad event of the gridd as this might trigger an infinite load loop on the page.

    Could would look something like below:

    Xrm.WebApi.retrieveRecord("entityA", "entityAGuid", "?$select=totalValue").then(
        function success(result) {
            // set the value of the read only field on the form
            formContext.getAttribute("totalValue").setValue(result.totalValue);
    
        },
        function (error) {
            console.log(error.message);
            // handle error conditions
        }
    );

    I hope this helps,

    Radu

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

Featured topics

Product updates

Dynamics 365 release plans