Skip to main content

Notifications

Announcements

No record found.

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

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Business Process flow with code

    Hello,

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

    Good luck.

  • Naresh ch Profile Picture
    5 on at
    RE: Business Process flow with code

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

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Business Process flow with code

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

  • satheesh k Profile Picture
    25 on at
    RE: Business Process flow with code

    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

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Business Process flow with code

    Try to use serviceClient.Create(workflow);

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Business Process flow with code

    Try to use serviceClient.Create(workflow);

  • satheesh k Profile Picture
    25 on at
    RE: Business Process flow with code

    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
    RE: Business Process flow with code

    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
    RE: Business Process flow with code

    hi Muhammet ATALAY ,

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

  • Muhammet ATALAY Profile Picture
    60 on at
    RE: Business Process flow with code

    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.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans