Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Business Process flow with code

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
    a33ik 84,323 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
    Naresh ch 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
    a33ik 84,323 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
    satheesh k 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
    a33ik 84,323 Most Valuable Professional on at
    RE: Business Process flow with code

    Try to use serviceClient.Create(workflow);

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

    Try to use serviceClient.Create(workflow);

  • satheesh k Profile Picture
    satheesh k 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
    a33ik 84,323 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
    satheesh k 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
    Muhammet ATALAY 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

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