locked
How to delete a Contract detail and associated records? RRS feed

  • Question

  • We have CRM 2011 on premises. I am trying to cancel a contract detail without cancelling its parent contract.

    Questions:

    1) I found this code online:

    TargetDeleteContractDetail target = new TargetDeleteContractDetail();
     target.EntityId = new Guid(someGuid);
     
    DeleteRequest delete = new DeleteRequest();
     delete.Target = target;
     DeleteResponse deleted = (DeleteResponse)service.Execute(delete);
    

    but TargetDeleteContractDetail is not coming up as a valid class.  In what namespace and in what dll does it reside?

    2) Is there an alternate way of accomplishing this?

    3) We have a custom entity, call it "D", which has an N:1 relationship with Contact.  D also has a relationship with a Contract Detail, call it "CD", as follows, where "X" is an entity that just connects the two.

    When I cancel the contractdetail, I also have to delete all entity records X, that connect to all entity records D for that Contract Detail.

    Please advise how to accomplish this.

    Thank you.

    Friday, December 27, 2013 6:59 PM

Answers

  • I solved my own problem: I used this code instead and it worked...

     try
                    {
                        SetStateRequest req = new SetStateRequest()
                        {
                            EntityMoniker = new EntityReference
                            {
                                Id = gEnrollmentId,
                                LogicalName = Xrm.ContractDetail.EntityLogicalName
                            },
                            State = new OptionSetValue(2),       // 2 = Cancelled
                            Status = new OptionSetValue(3)
                        };
    
                        SetStateResponse stateSet = (SetStateResponse)_service.Execute(req);
    
                    }

    • Marked as answer by MeProgrammer Monday, December 30, 2013 9:26 PM
    Monday, December 30, 2013 9:26 PM