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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Programatically Disabling a Business Rule

(0) ShareShare
ReportReport
Posted on by 22

I am trying to programatically disable a Business Rule using the SDK.

I am retrieving the Business Rule by retrieving the appropriate workflow record, making sure I select the 'Activation' record (Type=2), rather than the Definition Record, and retrieving the currently active record.

I've tried using a SetStateRequest, an UpdateRequest and a plain old Update. In every case I get the error message: "Cannot update a published workflow definition."

I've used similar code in the past to deactivate SDK message processing steps, but cannot figure how to get it to work for a Business Rule. Is there a different entity I should be trying to update, rather than workflow?

Thanks,

Ben

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Ben,

    My recommendation - check how Microsoft does it - open activate rule, run Fiddler, deactivate rule, stop Fiddler, check how Microsoft code does it.

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    Hi 

    I tried with the following code to activate and deactivate a BR and it seems to work fine


    // Activate
    var activateRequest = new SetStateRequest
    {
    EntityMoniker = new EntityReference
    ("workflow", new Guid("37878d0561edea11a815000d3a7f1b13")),
    State = new OptionSetValue(1),
    Status = new OptionSetValue(2)
    };
    CrmService.Execute(activateRequest);

    // De-activate
    var deActivateRequest = new SetStateRequest
    {
    EntityMoniker = new EntityReference
    ("workflow", new Guid("37878d0561edea11a815000d3a7f1b13")),
    State = new OptionSetValue(0), 
    Status = new OptionSetValue((1)  
    };
    CrmService.Execute(deActivateRequest );

    Hope this helps

  • Suggested answer
    Ben  Walker Profile Picture
    22 on at

    Hi both, thanks for the reply.

    Andrew, I tried what you suggested but couldn't really work out what was going on from what Fiddler was showing me.

    Kokulan, I got your code working. I realised my mistake - when querying the Busines Rule I was looking for records where type=2, which is the activation record. In fact I should have been selecting the records where type = 1 (definition). I thought that I'd already tried this but obviously not - all working fine now as long as you select type=1.

    Thanks again,

    Ben

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 131 Super User 2026 Season 1

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 46 Most Valuable Professional

#3
NeerajPawar Profile Picture

NeerajPawar 41

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans