Skip to main content

Notifications

Dynamics 365 general forum

[Dynamics 365 Online] Tracing Service and Workflow Context Null on Workflow Activity

Posted on by Microsoft Employee

Hi,

Currently I need help for Workflow Activity. Please take a look at code below:

protected override void Execute(CodeActivityContext executionContext)
{
	// Create the tracing service
	ITracingService tracingService = executionContext.GetExtension<ITracingService>();

	if (tracingService == null)
	{
		throw new NullReferenceException("Failed to retrieve tracing service.");
	}

	tracingService.Trace("Entered ProposeCaseActivity.Execute(), Activity Instance Id: {0}, Workflow Instance Id: {1}",
		executionContext.ActivityInstanceId,
		executionContext.WorkflowInstanceId);

	// Create the context
	IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();

	if (context == null)
	{
		throw new NullReferenceException("Failed to retrieve workflow context.");
	}

	tracingService.Trace("ProposeCaseActivity.Execute(), Correlation Id: {0}, Initiating User: {1}",
		context.CorrelationId,
		context.InitiatingUserId);

	IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
	IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
	CrmServiceContext serviceContext = new CrmServiceContext(service);
}


Why do the tracing service and also the workflow context are null? What is happening? Doesn't it the default code for a Dynamics Workflow Activity?

Thanks in advance.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: [Dynamics 365 Online] Tracing Service and Workflow Context Null on Workflow Activity

    Do you got an answer to this question?

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans