Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create an inactive record by plugin in CRM 2011?

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
like image 844
jcjr Avatar asked Jul 18 '13 11:07

jcjr


People also ask

How do I delete a record in CRM?

service. Execute(setState) will deactivate the record.

How do I create a record in Dynamics 365?

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.


2 Answers

You need to create the record first and after deactivate with a SetStateRequest.

There are no other ways to proceed.

like image 187
Guido Preite Avatar answered Nov 06 '22 19:11

Guido Preite


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.

Update

Since CRM 2015 U1, you shouldn't be using the SetStateRequest. Just use a standard update statement inside the Post Create.

like image 26
Daryl Avatar answered Nov 06 '22 18:11

Daryl