Is there way to create an inactive record by plugin in Microsoft CRM 2011? I can use setStateRequest
class and IOrganizationService.Execute
method to change state/status of an existing record. Since this method needs the record Id, It can't be use on a new record.
Is it possible to create immediately an inactive record or do I have to create a new active record and deactivate it after the creation?
Setting the state/status directly (even on a new record)
EntityToSave["statecode"] = new OptionSetValue(state);
EntityToSave["statuscode"] = new OptionSetValue(status);
leads to an error:
2 is not a valid status code for state code ProductState.Active on product
service. Execute(setState) will deactivate the record.
Select Automatic Record Creation and Update Rules. To create a record creation and update rule, select New. To edit an existing rule, in the list of rules, select and open the rule you want to edit.
You need to create the record first and after deactivate with a SetStateRequest
.
There are no other ways to proceed.
I would think you should be able to register a plugin that runs during the Post-operation step on the create message, that updates the entity to inactive using the SetStateRequest. As long as it is the first plugin to fire, everything else in the system is going to see it as being created in an inactive state.
This will cause any SetStateDynamicEntity plugins to execute, but you can use plugin execution variables to handle that as well.
Since CRM 2015 U1, you shouldn't be using the SetStateRequest. Just use a standard update statement inside the Post Create.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With