web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Workflows and plugins

(0) ShareShare
ReportReport
Posted on by 1,703

CRM2016 on premises

Whilst writing a plugin, I received a lot of help writing a function to query the calendar for 'working day dates' as this was needed to calculate a payment date from an imported file

In all there are three function that deal with non working dates and return a 'next' valid date. This all work fine in a plugin, however, I now have the same requirement but within a workflow.  What I am getting confused and stuck on is that in a plugin, the service provider is passed to the function, but in a workflow there is no iService Provider. Any suggestion on how to adapt the function or to what to palm in instead of serviceprovider

        Public Function CheckWorkingDay(serviceProvider As IServiceProvider, datetotest As DateTime) As Boolean
            If (IsItWeekend(datetotest)) OrElse (CheckHolidays(datetotest, serviceProvider)) Then
                Return False
            Else
                Return True
            End If
        End Function


*This post is locked for comments

I have the same question (0)
  • Moshe Hayun Profile Picture
    365 on at

    Hi,

    Inside a plugin, the IServiceProvider is passed to you as parameter. It's the entry point of the plugin.

    Have a look at this: msdn.microsoft.com/.../gg328263.aspx

  • Pete_N Profile Picture
    1,703 on at

    Hi thank you for your help, though I don't think you understood the question. I know about using IServiceProvider in a plugin, however, I'm trying to use the function that works in a Plugin ... but in a custom workflow where IServiceProvider is not passed as a parameter

  • Moshe Hayun Profile Picture
    365 on at

    Oops! Sorry, I misundestood the question.

    Why do you need the IServiceProvider? I guess that you have to use it to instance a service or something like that in the CheckHolidays function. If it's true, you have it in the CodeActivityContext parameter at the entry point of the workflow.

  • Pete_N Profile Picture
    1,703 on at

    Hi Thanks for the reply,  I am hoverer still in the dark on what I would need to pass through to this function

          Protected Overrides Sub Execute(executionContext As CodeActivityContext)

               Dim context As IWorkflowContext = executionContext.GetExtension(Of IWorkflowContext)()

               Dim serviceFactory As IOrganizationServiceFactory = executionContext.GetExtension(Of IOrganizationServiceFactory)()

               Dim service As IOrganizationService = serviceFactory.CreateOrganizationService(context.UserId)

  • Verified answer
    Moshe Hayun Profile Picture
    365 on at

    Are you talking about the parameter passed to your Execute function ? You have nothing to pass to this function. It's like the Main(string[] args) in a console app.

    CRM will automatic pass the context as parameter. Your code seems good.

    Once your dll deployed, you will see yoir Dll's namespace in the list of actions possible inside a workflow.

    I hope I answered your question.

  • RH-30102145-0 Profile Picture
    on at

    Check out this solution, which allows you to trace within a workflow:  https://spandcrm.com/2017/07/31/dynamics-setting-up-tracing-on-custom-workflow-steps-c/ 

  • RH-30102145-0 Profile Picture
    on at

    my code:

    ITracingService tracingService = executionContext.GetExtension<ITracingService>();

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans