Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Workflows and plugins

Posted on by 1,695

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

  • RE: Workflows and plugins

    my code:

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

  • RE: Workflows and plugins

    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/ 

  • Verified answer
    Moshe Hayun Profile Picture
    Moshe Hayun 365 on at
    RE: Workflows and plugins

    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.

  • Pete_N Profile Picture
    Pete_N 1,695 on at
    RE: Workflows and plugins

    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)

  • Moshe Hayun Profile Picture
    Moshe Hayun 365 on at
    RE: Workflows and plugins

    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
    Pete_N 1,695 on at
    RE: Workflows and plugins

    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
    Moshe Hayun 365 on at
    RE: Workflows and plugins

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans