locked
Updateing a phonecall, if contacts details change RRS feed

  • Question

  • Hi Everybody,

    i'm new to crm development and i started with developing plugins. In my current plugin I want to update phonecalls, if the contact details change. Most of the code seems to work. But I can not update the phonecall entity via the CRM Web Service.

    What i have done so far:

    log("Creating new Condition");
    ConditionExpression condition = new ConditionExpression();
    condition.AttributeName = "partyid";
    condition.Operator = ConditionOperator.Equal;
    condition.Values = new string[] { key.Value.ToString() };      
    
    log("Building Filter");
    FilterExpression filter = new FilterExpression();
    filter.FilterOperator = LogicalOperator.And;
    filter.Conditions.Add(condition);
    
    log("Building LinkEntity");
    LinkEntity link = new LinkEntity();
    link.LinkCriteria = filter;
    link.LinkFromEntityName = EntityName.activitypointer.ToString();
    link.LinkFromAttributeName = "activityid";
    link.LinkToEntityName = EntityName.activityparty.ToString();
    link.LinkToAttributeName = "activityid";
    
    log("Building Query");
    QueryExpression query = new QueryExpression();
    query.EntityName = EntityName.activitypointer.ToString();
    query.ColumnSet = new AllColumns();
    query.LinkEntities.Add(link);
    
    log("Building Request");
    RetrieveMultipleRequest request = new RetrieveMultipleRequest();
    request.Query = query;
    request.ReturnDynamicEntities = true;
    
    log("Firing Request");
    RetrieveMultipleResponse response = (RetrieveMultipleResponse)service.Execute(request);
    
    log("ForEach");
    foreach (DynamicEntity singleEntiy in response.BusinessEntityCollection.BusinessEntities) 
    { 
     EntityNameReference refe = (EntityNameReference) singleEntiy["activitytypecode"];
     if (refe.Value.Equals(EntityName.phonecall.ToString())) 
     {
       singleEntiy["subject"] = "Meeting with " + contact["firstname"];
                
       log("Try Updating Phone Call: " + contact["firstname"]);
       TargetUpdateDynamic updatedDynamicEntity = new TargetUpdateDynamic();
       updatedDynamicEntity.Entity = singleEntiy;
       UpdateRequest updateRequest = new UpdateRequest();
       updateRequest.Target = updatedDynamicEntity;
       log("UPDATE!!!!");
       UpdateResponse updateResponse = (UpdateResponse)service.Execute(updateRequest);
      }
    
    }
    log("Finished");
    

    After altering a contact in CRM. I got the following error message: "Object reference not set to an instance of an object". The last entry in my log is: UPDATE !!!

    Thanks for your help in advance

     

    Chris

     

    Tuesday, November 16, 2010 1:06 PM

Answers

  • Sorry that i mixed up deployment with development. That was my fault.
    • Marked as answer by homeyJPS Tuesday, November 16, 2010 3:02 PM
    Tuesday, November 16, 2010 3:02 PM

All replies

  • I fixed the problem. I "altered" the query, so that i can be sure to receive phonecalls in from my request.

    Greets

    Chris

    Tuesday, November 16, 2010 2:59 PM
  • Sorry that i mixed up deployment with development. That was my fault.
    • Marked as answer by homeyJPS Tuesday, November 16, 2010 3:02 PM
    Tuesday, November 16, 2010 3:02 PM