Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to get my custom workflow name in Custom Workflow code

Posted on by 320

How to get my custom workflow name in Custom Workflow code

*This post is locked for comments

  • Suggested answer
    Owerker Profile Picture
    Owerker 5 on at
    RE: How to get my custom workflow name in Custom Workflow code

    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();

  • sai123456 Profile Picture
    sai123456 320 on at
    RE: How to get my custom workflow name in Custom Workflow code

    Thanks Everyone. I will use the Class name followed by method name for tracing.

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: How to get my custom workflow name in Custom Workflow code

    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.

  • Suggested answer
    Mahadeo Matre Profile Picture
    Mahadeo Matre 17,021 on at
    RE: How to get my custom workflow name in Custom Workflow code

    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..

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: How to get my custom workflow name in Custom Workflow code

    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.

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How to get my custom workflow name in Custom Workflow code

    Sai, WHAT IS CUSTOM WORKFLOW???? IS IT WORKFLOW OR CUSTOM WORKFLOW ACTIVITY???

    I'm not stupid so please don't put emphases using caps.

  • sai123456 Profile Picture
    sai123456 320 on at
    RE: How to get my custom workflow name in Custom Workflow code

    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.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How to get my custom workflow name in Custom Workflow 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.

  • sai123456 Profile Picture
    sai123456 320 on at
    RE: How to get my custom workflow name in Custom Workflow code

    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

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How to get my custom workflow name in Custom Workflow 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.

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans