web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Business Process flow with code

(0) ShareShare
ReportReport
Posted on by

How can I create Bussiness Process flow with code. I can create workflow(ondemand/realtime ) with Xaml and below code.

Category = new OptionSetValue((int)WorkflowCategory.Workflow),
    PrimaryEntity = Opportunity.EntityLogicalName,
    Mode = new OptionSetValue((int)WorkflowMode.Background),

    // Additional settings from the second New Process form.
    Description = @"When an opportunity is created, this workflow" +
        " sets the closeprobability field of the opportunity record to 40%.",
    OnDemand = false,
    Subprocess = false,
    Scope = new OptionSetValue((int)WorkflowScope.User),
    TriggerOnCreate = true,
    AsyncAutoDelete = true,
    Xaml = xamlWF,

I changed category as new OptionSetValue((int)WorkflowCategory.BusinessProcessFlow) but no luck struck with an error


Message: An unexpected error occurred.

Any help is very appreciated.

Thanks in advance!!

 

 

*This post is locked for comments

I have the same question (0)
  • Muhammet ATALAY Profile Picture
    60 on at

    Workflow workflow = new Workflow()
    {
    // These properties map to the New Process form settings in the web application.
    Name = "Business Process Flow for new_test",
    Type = new OptionSetValue((int)WorkflowTypeEnum.Definition),
    Category = new OptionSetValue((int)WorkflowCategoryEnum.BusinessProcessFlow),
    PrimaryEntity = nameoftheEntityBPFtobeCreatedfor,
    Mode = new OptionSetValue((int)WorkflowModeEnum.Realtime),

    // Additional settings from the second New Process form.
    Description = @"it is a sample of BPF creation through C#.",
    OnDemand = false,
    Subprocess = false,
    Scope = new OptionSetValue((int)WorkflowScopeEnum.Organization),
    //TriggerOnCreate = true,
    //AsyncAutoDelete = true,
    Xaml = xamlWF,

    // Other properties not in the web forms.
    LanguageCode = 1033, // U.S. English
    };

    it works

    good luck.

  • satheesh k Profile Picture
    25 on at

    hi Muhammet ATALAY ,

     can you please share what are the packages we need to install for this in visual studio

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Satheesh, that's called "Early Bound" - learn.microsoft.com/.../early-bound-programming

    Here is a KB that describes on how to generate those classes - learn.microsoft.com/.../generate-early-bound-classes

    Good luck.

  • satheesh k Profile Picture
    25 on at

    hi a33ik 

    I have generated Early Bound class but I am getting this error[cannot convert from earlybound.workflow to Microsoft.Xrm.Sdk.organizationRequest]

    can you please advise

    Screenshot-_2800_381_2900_.png 

    if (serviceClient.IsReady)
    {
    Workflow workflow = new Workflow();
    // these properties map to the new process form settings in the web application.
    workflow.Name = "testprocess";
    workflow.Type = new OptionSetValue((int)workflow_type.Definition);
    workflow.Category = new OptionSetValue((int)workflow_category.BusinessProcessFlow);
    workflow.PrimaryEntity = "new_bankaccount";
    workflow.Mode = new OptionSetValue((int)workflow_mode.Realtime);
    // additional settings from the second new process form.
    workflow.Description = @"it is a sample of bpf creation through c#.";
    workflow.OnDemand = false;
    workflow.Subprocess = false;
    workflow.Scope = new OptionSetValue((int)workflow_scope.Organization);
    //triggeroncreate = true,
    //asyncautodelete = true,
    workflow.Xaml = "xamlwf";
    workflow.LanguageCode = 1033; // u.s. english
    serviceClient.Execute(workflow);

    // serviceClient.Create(workflow);

    }

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Try to use serviceClient.Create(workflow);

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Try to use serviceClient.Create(workflow);

  • satheesh k Profile Picture
    25 on at

    Hi a33ik ,

    I tried with serviceClient.Execute(workflow) & serviceClient.Create(workflow) , also getting this error[Error generating UiData for workflow:testprocess, id:b335dccb-437d-ed11-81ac-6045bd0061eb]

    pastedimage1671196951776v1.png

    Kind regards,

    Satheesh K

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Then, it's up to you to troubleshoot and figure out how it should work. Good luck.

  • Naresh ch Profile Picture
    5 on at

    Hi a33ik 

    I used early bound class for creating business process flow but it was saying work flow step is needed 

    Can you please share code of adding stage in business process flow

    Thanks in advance !!

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    I haven't done that before. As I mentioned earlier - it's up to you to find and fix the issue.

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans