Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Microsoft Dynamics 365 Extensions Cookbook

You're reading from   Microsoft Dynamics 365 Extensions Cookbook Add functionality to existing model elements, source code and finally package and deploy using DevOps

Arrow left icon
Product type Paperback
Published in Jun 2017
Publisher Packt
ISBN-13 9781786464170
Length 462 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Rami Mounla Rami Mounla
Author Profile Icon Rami Mounla
Rami Mounla
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. No Code Extensions FREE CHAPTER 2. Client-Side Extensions 3. SDK Enterprise Capabilities 4. Server-Side Extensions 5. External Integration 6. Enhancing Your Code 7. Security 8. DevOps 9. Dynamics 365 Extensions 10. Architectural Views 11. Dynamics 365

Setting up the rollup fields

Rollup fields are one of the most exciting new features that were introduced in recent years that significantly reduced the amount of custom code required. Rollup fields can aggregate values from other attributes. You can calculate sums, averages, minimums, maximums, and counts.

In this recipe, we will create a rollup field that counts how many active activities are associated with a contact.

Getting ready

Similar to the previous recipes, a System Customizer or higher security role is required to perform the configuration as well as a solution to contain the changes.

How to do it

  1. Navigate to Settings | Solutions | Packt.
  2. Create a new field by clicking on Entity | Contact | Fields | New and enter the following details:
    • Display Name: Number of Activities
    • Data Type: Whole Number
    • Field Type: Rollup
  3. Click on Edit next to the Field Type dropdown.
  4. In the Rollup Field dialog, under Related Entity, select Activities (Regarding) and click the tick box.
  5. In the Filters section, select the following:
    • Activity Status under Field
    • Equals under Operator
    • Value under Type
    • Check Open and Scheduled under Value
  6. Click on the tick box.
  7. Under Aggregation, select the following:
    • Aggregate Function under Count
    • Activity under Aggregated Related Entity field
  8. Click on the tick box. Your ROLLUP FIELD dialog will look as follows:
  1. Click on Save and Close on the ROLLUP FIELD dialog and the attribute dialogue.
  2. Click on the Publish All Customizations button for your solution.

How it works...

In step 2 to step 7, we created a new rollup field of type whole number that calculates the total count of active activities associated with a contact.

A couple of things to note about rollup fields: the fields are read-only and the calculation does not take into account a user's security roles.

Frequency

When a rollup field is created, behind the scenes, a system asynchronous job is scheduled to execute 12 hours after the field is created. Navigate to Settings | System Jobs; you will see a job of type Mass Calculate Rollup field with the name of your new field in System Job Name. You can force the job to run sooner by clicking on Action | Postpone and entering an earlier date/time. It is not recommended to do so when you have a large number of records in a production environment. The first time the job runs, it will have to update all fields, which might lead to a performance impact.

Subsequently, the System Jobs option will have a Calculated Rollup field per entity that has rollup fields configured. By default, subsequent rollup field calculations will take place every hour, (which is the fastest schedule). If an hourly update is not necessary, you can update the value by double-clicking on the System Job option, and selecting Actions | Modify Recurrence. This will present a dialog box that helps you redefine the recurrence of the execution:

Given that the rollup fields are executed as asynchronous jobs, if the calculation is not occurring, consider checking the status of the asynchronous service. For on-premise installation, log on to your backend server and check its status. For online implementations, log a support call with Microsoft to check the status of the service.

Programmatic Rollup Field execution

On top of the automated schedules, rollup fields can also be executed programmatically by executing CalcualteRollupFieldRequest. Furthermore, if you search online for "rollup field workflow", you will find custom workflow activities built by the community to force recalculations in your configurable workflows.

There's more...

Rollup fields are a powerful feature in Dynamics 365. On top of the counting capability described in this recipe, rollup fields offer other types of aggregations. Furthermore, in some cases (activities), the aggregation can span across multiple relationship levels.

Different types of aggregation

Counting the number of records is one of the many capabilities of a rollup field. You can also get the maximum, minimum, average, and sum of a field, assuming the field type allows it. As you select a different aggregate function, the entity fields will be filtered accordingly.

Indirectly related activities

Given that our rollup field is aggregating activities, the field can also include indirectly related activities by defining Activity Parties (activities) under indirectly related activities. This will expand the aggregation, not only when the contact is in the regarding field, but also in the parties field.

For more details about rollup fields, visit https://technet.microsoft.com/en-nz/library/dn832162.aspx.

See also

  • Setting up calculated fields
You have been reading a chapter from
Microsoft Dynamics 365 Extensions Cookbook
Published in: Jun 2017
Publisher: Packt
ISBN-13: 9781786464170
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image