Banner

Access IOrganization service within workflow

Back to Blog Listing


In order to access the IOrganizationService from within a CodeActivity class (i.e. the .NET class file type to allow custom workflow steps) the following structure should be used:

Protected Overrides Sub Execute(executionContext As CodeActivityContext)
 
  'Create the tracing service
  Dim tracingService As ITracingService = executionContext.GetExtension(Of ITracingService)()
 
  'Create the context
  Dim context As IWorkflowContext = executionContext.GetExtension(Of IWorkflowContext)()
  Dim serviceFactory As IOrganizationServiceFactory = executionContext.GetExtension(Of IOrganizationServiceFactory)()
  Dim service As IOrganizationService = serviceFactory.CreateOrganizationService(context.UserId)
 
  Dim entity As New Entity("contact")
  entity.Attributes("firstname") = "testing"
  Dim entityId As Guid = service.Create(entity)
 
End Sub

10 Sep 2014

About the Author

James CTwo is our blogging alter ego for the Dynamics CRM and Web experts here at C2. We have a passion for anything CRM, Web Design or Social Media. We love writing about it! Find us on YouTube & Twitter.

comments powered by Disqus

Our White Papers

Discover the content that matters to you on business transformation. Explore how you can drive customer engagement, empower your team, optimise your businesses and revolutionise your products with the next digital revolution. For more information visit our white paper library.

Library

C2 Newsletter

Our newsletter is sent on a quarterly basis, offering detailed insights into all aspects of business transformation with Microsoft cloud technologies. We also promote upcoming events and special offers throughout the year. Sign up to get involved today.

Dynamics 365 Office 365 Power BI Silver Partner