I am trying to delete a contract line ("test1") from contractdetail entity associated to an active contract but getting the following error.
Following the same code I can successfully change "contract" entity status to cancel but when trying to cancel contractdetail it fails.
The error occurs at this step.
var setStateResponse = (SetStateResponse)_service.Execute(setStateRequest);
Code:
QueryExpression contractQuery = new QueryExpression() { EntityName = "contractdetail", ColumnSet = new ColumnSet("title", "activeon" , "expireson" , "totalallotments", "productid", "customerid", "price", "statuscode", "statecode" ), Criteria = { Conditions = { new ConditionExpression("contractid", ConditionOperator.Equal, new Guid(contract.Id.ToString())) } } }; EntityCollection contractDetails = _service.RetrieveMultiple(contractQuery); Entity contractLine = null; foreach (Entity contractLineItem in contractDetails.Entities) { string title = contractLineItem.Attributes["title"].ToString(); if (contractLineItem.Attributes["title"].ToString() == "test1") { contractLine = contractLineItem; break; } } if (contractLine != null) { try { //Cancel line item /*contractLine["contractid"] = new Guid(contractLine.Id.ToString()); contractLine["statecode"] = new OptionSetValue(2); //cancel contractLine["statuscode"] = new OptionSetValue(3); //cancel var request = new UpdateRequest(); request.Target = contractLine; request.Parameters = new ParameterCollection() var response = (UpdateResponse)_service.Execute(request);*/ var setStateRequest = new SetStateRequest() { EntityMoniker = new EntityReference { LogicalName = "contractdetail", Id = new Guid(contractLine.Id.ToString()) },
State = new OptionSetValue(2), //inactive Status = new OptionSetValue(3) //inactive };
var setStateResponse = (SetStateResponse)_service.Execute(setStateRequest); } catch (Exception ex) { }
Error:
<s:Envelope xmlns:s="schemas.xmlsoap.org/.../envelope"><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstring xml:lang="en-US">There is no active transaction. This error is usually caused by custom plug-ins that ignore errors from service calls and continue processing.</faultstring><detail><OrganizationServiceFault xmlns="schemas.microsoft.com/.../Contracts" xmlns:i="www.w3.org/.../XMLSchema-instance"><ActivityId>da14a7bc-dc28-4bd8-81b8-b80f2d1ceee2</ActivityId><ErrorCode>-2147220911</ErrorCode><ErrorDetails xmlns:a="schemas.datacontract.org/.../System.Collections.Generic"/><Message>There is no active transaction. This error is usually caused by custom plug-ins that ignore errors from service calls and continue processing.</Message><Timestamp>2017-08-11T16:13:22.832296Z</Timestamp><ExceptionRetriable>false</ExceptionRetriable><ExceptionSource i:nil="true"/><InnerFault><ActivityId>da14a7bc-dc28-4bd8-81b8-b80f2d1ceee2</ActivityId><ErrorCode>-2147220911</ErrorCode><ErrorDetails xmlns:a="schemas.datacontract.org/.../System.Collections.Generic"/><Message>There is no active transaction. This error is usually caused by custom plug-ins that ignore errors from service calls and continue processing.</Message><Timestamp>2017-08-11T16:13:22.832296Z</Timestamp><ExceptionRetriable>false</ExceptionRetriable><ExceptionSource i:nil="true"/><InnerFault i:nil="true"/><OriginalException i:nil="true"/><TraceText i:nil="true"/></InnerFault><OriginalException i:nil="true"/><TraceText i:nil="true"/></OrganizationServiceFault></detail></s:Fault></s:Body></s:Envelope>
Any help would appreciated.
*This post is locked for comments