web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Update field after value update

(0) ShareShare
ReportReport
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.

I have the same question (0)
  • Verified answer
    Radu Chiribelea Profile Picture
    6,667 on at

    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

  • cmilanelo Profile Picture
    15 on at

    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!

  • Radu Chiribelea Profile Picture
    6,667 on at

    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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 107 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 92

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans