views:

42

answers:

2

Hi!

Im trying to update "StatE Code" (Active|Inactive) to Active through the CRM web service on a product in the database.

...
crmProduct.statecode = new ProductStateInfo() { Value = ProductState.Active };
//crmProduct.statuscode = new Status() { Value = 1 };
crmProduct.name = "...";
service.Update(crmProduct);

It seem to work okay, I get no errors and the name changes, but its still Inactive!

When trying to set "StatUS Code" as well to Active, I get an error saying I cant set status to Active when state is Inactive... but Im setting both to Active at the same time... hmmmm.. dont now whats wrong here...

Any clues?

+1  A: 

You have to use the SetStateDynamicEntityRequest to update the state of a record. You can update the statuscode using the regular update message, but only if the code you're updating to is in the same state that the record is currently in, as you've found.

Matt
+3  A: 

Setting the state code in an entity has no effect when you save it. You must use an appropriate SetState request. As Matt said, for dynamic entities this is the SetStateDynamicEntityRequest. In your case I am assuming you are using a "product" object, so you need to use the SetStateProductRequest class.

var request = new SetStateProductRequest()
{
  EntityId = [GUID of product],
  ProductState = ProductState.Active,
  ProductStatus = -1
}
var response = (SetStateProductResponse)crmService.Execute(request);

Check out this link: http://msdn.microsoft.com/en-us/library/bb958061.aspx

The -1 for the ProductStatus tells CRM to use to appropriate default statuscode value for the statecode.

BlackWasp