Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

Programatically Disabling a Business Rule

(0) ShareShare
ReportReport
Posted on by 11

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

  • Suggested answer
    Ben  Walker Profile Picture
    Ben Walker 11 on at
    RE: Programatically Disabling a Business Rule

    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

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,050 on at
    RE: Programatically Disabling a Business Rule

    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
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Programatically Disabling a Business Rule

    Ben,

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

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,969 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,842 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans