Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Call the OOB script to refresh a rollup field

Posted on by 361

i want to refresh a rollup field in my form but i don't know when i click on the small refresh button on the right of the rollup field which script is triggered is there anyway i can call the the function on my custom javascript so i can refresh the rollup field instead of using a plugin which recalculating in the server but not updating the form so i have manually do it

*This post is locked for comments

  • Verified answer
    Yusi Profile Picture
    Yusi 100 on at
    RE: Call the OOB script to refresh a rollup field

    Yes , the code below works perfect for me.


    function CalculateRollupField(EntityName, recGuid, RollUpFieldName)

    {
    recGuid = recGuid.replace("{", "").replace("}", ""); // String Guid

    var HttpReq = new XMLHttpRequest();

    HttpReq.open(this.method, this.url, true); // Need this to initiate the request

    HttpReq.setRequestHeader("OData-Version", "4.0");

    HttpReq.setRequestHeader("OData-MaxVersion", "4.0");

    // Double Check your API URL, may differ for v9.0
    HttpReq.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/" + "CalculateRollupField(Target=@p1,FieldName=@p2)?" + "@p1={'@odata.id':'" + EntityName + "(" + recGuid + ")'}&" + "@p2='" + RollUpFieldName + "'", true);

    HttpReq.onreadystatechange = function ()

    {

    if (this.readyState === 4)

    {

    HttpReq.onreadystatechange = null;

    if (this.status === 200)

    {

    var results = JSON.parse(this.response);

    }

    else

    {

    Xrm.Utility.alertDialog(this.statusText);

    }

    }

    };

    HttpReq.send(JSON.stringify({}));

    }


    You can then retrieve the updated value via JS API call and use XRM commands to replace the updated value in the form

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Call the OOB script to refresh a rollup field

    I don't think there is any OOB  script available to refresh the rollup fields.

  • Anas Rafik Profile Picture
    Anas Rafik 361 on at
    RE: Call the OOB script to refresh a rollup field

    yes i already created a synchronous plugin recalculating my field then i reloaded the entire form but i don't want to perform all of this i am searching form the oob script so i can trigger it from my javascript

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Call the OOB script to refresh a rollup field

    Hello,

    You can do using custom workflow activity and then using JavaScript html webresource create button  to refresh rollup fields-  

    Please check here -

    community.dynamics.com/.../calculate-rollup-fields-on-button-click

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans