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
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
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
Ben,
My recommendation - check how Microsoft does it - open activate rule, run Fiddler, deactivate rule, stop Fiddler, check how Microsoft code does it.
André Arnaud de Cal...
291,969
Super User 2025 Season 1
Martin Dráb
230,842
Most Valuable Professional
nmaenpaa
101,156