AXForum  
Вернуться   AXForum > Microsoft Dynamics CRM > Dynamics CRM: Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 31.07.2018, 17:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,617 / 848 (80) +++++++
Регистрация: 28.10.2006
crmtipoftheday: Tip #1144: How to add business days
Источник: https://crmtipoftheday.com/1144/how-...business-days/
==============

Over six months ago I got a tip from Sergio “Behind The Wall” Macías, part of the the driving force behind Spanish-speaking Dynamics 365 community, on how to create a custom workflow activity that adds business days to a specific date in Dynamics 365. In the essence, the calculations are something like this:

while(businessDaysToAdd > 0){ starDate = starDate.AddDays(1); if(IsBusinessDay(startDate)) businessDaysToAdd--;}The heart of calculations is, of course, the IsBusinessDay method that would skip obvious Saturdays and Sundays and then go through a holiday calendar to work out if the employees eat turkey instead of helping customers or if it’s business as usual (e.g. help customers eat turkey). (“Go through a holiday calendar” sounds much easier than it actually, is, trust me). I filed the tip with the intention to come back to it until the opportunity presents itself, i.e. until I have a chance to test-drive it using customer’s money, which happened just recently. Because of the vast Dynamics 365 community resources, regardless what the challenge is, I rarely feel the need to either create custom code from scratch or repurpose the existing code. On this occasion, I found two independent open source workflow libraries that would solve my challenge.

Andrii’s Ultimate Workflow Toolkit and Jason’s CRM DateTime Workflow Utilities both have Add Business Days methods though the approach and the parameters are slightly different. Both take existing date and number of days to add as an input, and have the result as an output but that’s where the similarities end.

CRM DateTime Workflow Utilities

The AddBusinessDays activity takes Holiday/Closure Calendar parameter that you can point to a holiday calendar specific for your organization / department / business unit. This is the same calendar that can be used in service scheduling to define availability of the resources. The only downside of the activity implementation is hard-coded Saturdays and Sundays as non-business days. It works in 99% of the cases but on odd occasion business needs to include some of the weekends.

Ultimate Workflow Toolkit

The AddBusinessDays activity in this toolkit does not use holiday calendar but instead takes extra two parameters: weekend days (as a string of numbers from 0 to 6 (Sun to Mon) delimited by ‘|’) and a Fetchxml expression that would return days to skip (holidays). This “developer-friendly” approach works well if your organization does not use calendars but instead keeps holidays in a custom entity.

Waiting

If you adding business days only with the purpose of waiting until the certain number of days passes e.g. remind customer of an unpaid invoice after 5 business days then you might want to consider codeless approach using SLAs.

Thanks to Andrii “Granny’s Moonshine” Butenko and Jason “I can make a kettle talk to CRM” Lattimer for their awesome contributions – I use their toolkits on a daily basis.

(Facebook and Twitter cover photo by Curtis MacNewton on Unsplash)



Источник: https://crmtipoftheday.com/1144/how-...business-days/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
crmtipoftheday: Tip #1134: Moving Users Between Business Units Blog bot Dynamics CRM: Blogs 0 16.07.2018 14:12
alexef: How to add a field to Item Card in Business Central Blog bot NAV: Blogs 0 22.05.2018 20:11
crmtipoftheday: Tip #1101: Add a scale break to charts Blog bot Dynamics CRM: Blogs 0 07.04.2018 04:03
crmtipoftheday: Tip #1099: Add Annotations to Charts Blog bot Dynamics CRM: Blogs 0 06.04.2018 06:15
crmtipoftheday: Tip #1095: Add percentage labels to pie charts Blog bot Dynamics CRM: Blogs 0 02.04.2018 04:16
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 01:19.