How to get my custom workflow name in Custom Workflow code
*This post is locked for comments
How to get my custom workflow name in Custom Workflow code
*This post is locked for comments
It is actually pretty easy nowadays
IWorkflowContext WorkflowContext = Context.GetExtension(); var parentWF = service.Retrieve("workflow", WorkflowContext.OwningExtension.Id, new ColumnSet(new String[] { "name" })); // then use parentWF.Attributes["name"].ToString();
Thanks Everyone. I will use the Class name followed by method name for tracing.
Hi Sai,
I agreed with Adrian and Ravi, You can't change workflow name so it's good to use hard coded name , you don't need to put extra effort for that?
In addition as Mahedeo suggested if you want to get the parent workflow name then pass input argument with workflow name or if I am not wrong you should have some kind of logic inside code to check when and what condition your parent workflow triggering , I mean you know better which name you need and when particular workflow triggering so just think if any way you can hard code the name.
If you need only for error handling then you don't need to pass workflow name parameter, as Ravi mentioned you can add workflow activity / class & method name in code.. I generally do error handling as follows
try
{
// Business logic
}
catch (Exception error)
{
tracingService.Trace("Caught Error Sending Customer Survey: {0} \n with stacktrace \n {1}", error.Message, error.StackTrace);
}
you can add custom workflow activity name / method in trace
tracingService.Trace("Class: AbcCorp.Xrm.WF.CustomerSurvey , Method: GetEmailTemplate, Error Details : {0} \n with stacktrace \n {1}", error.Message, error.StackTrace);
Hope this will help..
Hi Sai,
If you need this for error logging purpose then why don't you hardcode the name while generating the error log. Just by getting the workflow name may not give you the exact method, with harcoding you can have it harcode in some set form like <ClassName:MethodName>. And then store this value in your log entity.
tracingService.Trace(CustomTracer.LogLevel.Info, "SomeWorkflowName: SomeMethodInThatWorkflow: SomeCustomMessageForMoreDetail");
Hope this helps.
Sai, WHAT IS CUSTOM WORKFLOW???? IS IT WORKFLOW OR CUSTOM WORKFLOW ACTIVITY???
I'm not stupid so please don't put emphases using caps.
Andrew I need the CUSTOM WORKFLOW name inside the code. We have an entity to store Error Logs on Plugin and Workflow failure. It will be easy to trace if we can get workflow name in the code.
Check following post - docs.microsoft.com/.../sample-create-custom-workflow-activity
Put attention to following lines - declaration of input:
[Input("Account Name")]
[Default("Test Account: {575A8B41-F8D7-4DCE-B2EA-3FFDE936AB1B}")]
public InArgument<string> AccountName { get; set; }
usage of input inside the code:
string accountname = AccountName.Get<string>(executionContext);
Good luck.
Andrew, Mahadeo
I have input argument on the custom workflow but not sure how I can access the custom workflow name within the code. Can you guys help me with the code
Sai,
As Mahadeo suggested the easiest way to accomplish your goal is to add input parameters to your custom workflow activity - docs.microsoft.com/.../add-metadata-custom-workflow-activity and pass data that you need from workflow.
Good luck.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156