用webapi重新计算汇总字段的值

本文介绍了如何使用Dynamics 365 WebAPI和JavaScript触发汇总字段的即时重新计算。默认情况下,汇总字段每小时才会重新计算一次。如果需要立即显示汇总字段的结果,此方法可以确保获取最新数据。通过调用内置的CalculateRollupField函数,针对特定实体的特定字段执行此操作。文中以重新计算活动的出席人数为例,详细阐述了请求的构建和执行过程。
摘要由CSDN通过智能技术生成

Trigger Rollup Field Recalculation using Dynamics 365 WebAPI and JavaScript

A common operation that is performed when working with records in Microsoft Dynamics 365 is rollup field recalculation. This is because by default, rollups are only recalculated once every hour. If you have logic that requires you to present the result of a rollup field immediately (for reporting purposes, or verification purposes), it may be beneficial to recalculate the rollup field on demand in order to have the latest data.

This operation can be performed with the WebAPI using a built in ‘Function’. The documentation for this function can be found here:

CalculateRollupField Function (Microsoft.Dynamics.CRM) | Microsoft Docs,

and the documentation for performing functions can be found here:

Use Web API functions (Microsoft Dataverse) - Power Apps | Microsoft Docs.

For the purposes of the following examples, we’ll be recalculating the number of attendees for an event that we are hosting. The entity will be Event (mag_event), with the field being Number of Attendees (mag_numberofattendees).


The CalculateRollupField function is an unbound function, and takes two parameters – Target and FieldName. The basic syntax for performing an unbound function is as shown below.

  • GET [Organization URI]/api/data/v9.0/FunctionName(Param1=@p1,Param2=@p2)?@p1='p1 data'&@p2=123456 

Because the Target parameter of the CalculateRollupField function is of type crmbaseentity, this must be bound to an existing entity using the @odata.id attribute. Therefore, our function ends up looking as follows:

  • GET [Organization URI]/api/data/v9.0/CalculateRollupField(Target=@tid,FieldName=@fn)?@tid={'@odata.id':'mag_events(9f3162f6-804a-e611-80d1-00155d4333fa)'}&@fn='mag_numberofattendees'

When performed with JS, the request ends up looking like the following:

var requestUrl = Xrm.Page.context.getClientUrl() + "/api/data/v9.0/CalculateRollupField(Target=@tid,FieldName=@fn)?@tid={'@odata.id':'mag_events(9f3162f6-804a-e611-80d1-00155d4333fa)'}&@fn='mag_numberofattendees'"

var req = new XMLHttpRequest();
req.open("GET", requestUrl, false);
req.send();

Note that when the value is recalculated, it is not automatically refreshed on open forms. These forms will need to be refreshed manually, so this function is mostly useful when updating rollups from related entities.

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值