crm - Why error "The state is invalid"? -


we have crm 2011, on-premises. in wcf service (c#) programmatically creating contracts , contractdetails. after creating contract, set state = 'invoiced' using code:

try {    setstaterequest setstaterequest = new setstaterequest()    {        entitymoniker = new entityreference        {           id = gnewcontractid,           logicalname = xrm.contract.entitylogicalname        },        state = new optionsetvalue((int)xrm.contractstate.invoiced),        status = new optionsetvalue((int)xrm.contractstate.invoiced + 1)    };     _service.execute(setstaterequest);   } 

this process used work error, did today:

"system.servicemodel.faultexception`1[microsoft.xrm.sdk.organizationservicefault]: state invalid, contract cannot set invoice state. (fault detail equal microsoft.xrm.sdk.organizationservicefault)."

the state of contract when snippet executed (and failed today) 'draft'.

this contract has child contract details, , activeon date 6/1/2015, should have been made active - , was. not understanding error or need prevent it.

thanks , advice.

first line of code

status = new optionsetvalue((int)xrm.contractstate.invoiced + 1) 

should like

status = new optionsetvalue((int)xrm.contractstatus.invoiced) 

or name status reason enum generated, because writing 1+1, reduce function of bound.

regarding contract, looks setstaterequest acts differently based on start , end dates of contract. if range falls inside current date, request set contract active, if range falls outside current date, contract invoiced. please check contract dates , see if case.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -