Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

WebAPi rollupfields

(0) ShareShare
ReportReport
Posted on by 515

Does anyone know of sample code to update the rollupfields (in the current entity) using Web Api?

I've got the basic pages about it, but could do with a sample to get myself going in the right direction.

Thanks

Lee

  • Lee-Martin Profile Picture
    515 on at
    RE: WebAPi rollupfields

    Thank you

  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at
    RE: WebAPi rollupfields

    You have to do a new one every time.

  • Lee-Martin Profile Picture
    515 on at
    RE: WebAPi rollupfields

    One last question, I've got 5 fields I need to do, can I just add them to the same string (the line begining req.open(GET

    or will i have to do a new one every time?

  • meelamri Profile Picture
    13,216 User Group Leader on at
    RE: WebAPi rollupfields

    You are welcome.

  • Lee-Martin Profile Picture
    515 on at
    RE: WebAPi rollupfields

    Yep, put the right id in instead of incidentid in your code and it works fine

    Thanks for your help

  • Lee-Martin Profile Picture
    515 on at
    RE: WebAPi rollupfields

    I think I've got it, I've left some code dependant on your system, where i should change it that on mine.

  • Lee-Martin Profile Picture
    515 on at
    RE: WebAPi rollupfields

    function recaclulateRollupField(executionContext) {
        var formContext = executionContext.getFormContext();
        var recordId = formContext.data.entity.getId().replace("{", "").replace("}", "");
        var entityLogicalName = formContext.data.entity.getEntityName();
    	
    
    	var lastReviewRollup = "can_lastreview";
    	console.log("Lee - "   lastReviewRollup);
    	
    	
        var req = new XMLHttpRequest();
      //  console.log(calculatedRollupFieldReq);
        req.open("GET", Xrm.Utility.getGlobalContext().getClientUrl()   '/api/data/v9.2/CalculateRollupField(Target=@Target,FieldName=@FieldName)?@Target={"incidentid":"' recordId '","@odata.type":"Microsoft.Dynamics.CRM.' entityLogicalName '"}&@FieldName=\'' lastReviewRollup '\'', true);
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.onreadystatechange = function () {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200) {
                    //refresh
                    var results = JSON.parse(this.response);
                    formContext.data.refresh(false);
                    console.log(results)
                }
                else if (this.status === 400) {
                    //refresh
                    console.log("Lee - failure");
    				console.log("Lee - "   this.statusText);
                } else {
                    Xrm.Utility.alertDialog(this.statusText);
                }
            }
        };
        req.send();
    }

  • meelamri Profile Picture
    13,216 User Group Leader on at
    RE: WebAPi rollupfields

    Hi,

    I just tested my Script with a date rollup, it works without any problem. Can you please share your code and how you configure your handle, thank you :)

  • Lee-Martin Profile Picture
    515 on at
    RE: WebAPi rollupfields

    I'm getting a 400 error with it

  • Lee-Martin Profile Picture
    515 on at
    RE: WebAPi rollupfields

    The rollups are all date fields, and need to be timestamped to whenever the page is opened

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Adis Profile Picture

Adis 136 Super User 2025 Season 1

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 81

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 77 Super User 2025 Season 1

Product updates

Dynamics 365 release plans