Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Change/Cancel a Contract Line (contractdetail) from an active contract

Posted on by 141

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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans