RollupField is not recalculating

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

RollupField is not recalculating

RollupField – yes, nice CRM >= 2015 feature. Theoretically a cure for all previous “manual” calculations. Of course it has some limitations but this post is not about that. MSDN documentation contains these informations anyway.
Unfortunatelly I came across a major issue related with rollup field when it’s type is Money.


Let’s imagine an entityA which has a rollup field type Money. This is the only Money field in this entity. EntityA is related 1:N with Invoice entity. Automatically created TransactionCurrencyId field on entityA is not required on form. RollupField sum Invoice TotalAmount.

When record of entityA is created manually currency field is being set automatically. But when record is created via plugin/SSIS then currency is not being set automatically – developer needs to take care of that.
I came accross such a situation recently and the first-thought solution was not working as supposed.

Solution 1 – failed

Ok, no problem I thought. Quick google and found a solution – MSDN says: for money field, even rollup, there must be a currency field set on the form.
I have created a workflow which sets the currency and updates a record. After that I have manually run MassCalculate system job. Phhii, piece of cake, isn’t it?
I was so surprised when it occures that currency field is set but corresponding ExchangeRate on the form is not and RollupField is not calculating.

Lesson learnt: not only Currency but also ExchangeRate fields needs to be set for RollupField to be calculated. ExchangeRate is being set on create once TransactionCurrencyId is set.


Solution 2 – failed

Interesting. Setting currency via worfklow is not enough for RollupFields. Fine.
Lets create a custom workflow activity which will delete current currency lookup, saves the records, set the currency back with setting additionaly the exchange rate field and saves back again.
This solution in fact lead to a situation that all required fields (for money rollup calculation) are set but rollup is semi-calculated. But it doesn’t schedule the calculations.



Let’s do a combo now. Only after executing steps from step2 + running MassCalculate job manually + running a CalculateRollupFieldRequest for each entity separatelly (manually, workflow, some client’s application) I was able to successfully start the scheduled calculations. It is worth remembering especially at early 2015 versions.

Lesson learnt: set the Currency field at the beginning, expecially for the RollupFields.

Have an own opinion?