Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Setting statuscode and statecode On Entity Create... Not as a seperate SDK call.

$
0
0

I'm having some trouble seeing how to set the state codes on a new entity record create.  I can set it after the entity is created but I don't want to have to make a seperate call.  So the examples that show you do a seperate state request just to set it, that is not what I want to do... unless I have no other choice.

I'm insterting around 10,000 records at a time into CRM and I am rewriting code that we hired an outside consulting company to develop.  That code takes about 4 to 7-hours to run.... really!  I see a LOT of bad things in the code, such as datasets, datatables, text files, and many dozens of calls out to the SDK for each entity that is created or updated.  So I tossed that app altogether and started back from scratch to develop my own.  My current version runs in about 30-minutes.  But I still see areas for improvement, by reducing the number of calls to the SDK.  But I cannot figure out how to set the state codes when creating an new entity record.  I can only see how to do that after it has been created and by using a seperate SDK call.

When we are creating new entities, I want to set the state and status code and then do a single SDK call to create the record.  I figured out that you can set the statuscode just like any other attribute in the new entity.  But it doesn't appear that you can do the same on the state code.  Does anyone know if you can use this approach and set both of these on the new entity so that you only have to execute a single .Create(newEntity) and call the SDK only once?

I did find another reference that said you cannot set the statecode, but you can set the statuscode, so maybe this is just not possible.  But I would like to confirm this before giving up and doing a second call.

.Attributes["statuscode"] = new OptionSetValue(statuscode));  // This works.                                   
.Attributes["statecode"] = new OptionSetValue(stateCode));  // This does not.                                   

Jon Gregory Rothlander




Viewing all articles
Browse latest Browse all 8223

Trending Articles