I need to add the custom holiday fields in Dynamics v9.
The thing that I'm trying to achieve looks like this:
I have two date(a and b) fields and one rollup field, which calculates the difference between a and b.
This calculation must take into the consideration my custom holidays, which I have to somehow feed into the system.
What are the possible solutions for my goal ?
Thanks
With calculated fields you can do some basic computations using conditions and some basic formulas. For working with dates a few functions are available, like DIFFINDAYS()
, but I guess these will not be of much use when holidays or weekends need to be respected.
You wrote you have fed custom holidays into the system. Unfortunately using these data will prove to be hard or even impossible. Fact is you can actually use values of related records in your calculation, but the related record must be accessed through a lookup on the same record your computational field resides on. It is not possible to use a smart query and get the proper data out of the system on the fly using start and end dates.
See also Create a calculated field to automate manual calculations.
Best advice I can give is creating a plugin that is triggered on the PreCreate and PreUpdate stages of your entity. When start or end date changes, this plugin simply adds the updated day counting field to the target entity accordingly.
Keep in mind you cannot write values to calculated fields. The solution with a plugin doing the calculation requires a standard field (integer or string).