locked
Update plugin using ExecuteMultipleRequest RRS feed

  • Question

  • Hi,

    I want to update a lookup field through plugin. But nothing is happening on execution.

    Is it the correct way of doing?

    try{
    
    var fetch=@"<fetch distinct="false" mapping="logical" output-format="xml-platform" version="1.0">
    <entity name="task">
    <attribute name="regardingobjectid"/>
    <attribute name="new_taskphase"/>
    <filter type="and">
    <condition attribute="statecode" value="2" operator="eq"/>
    </filter>
    </entity>
    </fetch>";
    
    EntityCollection ec = service.RetrieveMultiple(new FetchExpression(fetch));
    if(ec.Entities.Count>0)
    {
      // Create an ExecuteMultipleRequest object.
                            ExecuteMultipleRequest multipleRequest = new ExecuteMultipleRequest()
                            {
                                // Assign settings that define execution behavior: continue on error, return responses. 
                                Settings = new ExecuteMultipleSettings()
                                {
                                    ContinueOnError = false,
                                    ReturnResponses = true
                                },
                                // Create an empty organization request collection.
                                Requests = new OrganizationRequestCollection()
                            };
    
    			 foreach (var item in ec.Entities)
                 {
    			 item.Attributes["new_taskphase"]="Completed";
                  UpdateRequest updateRequest=new UpdateRequest{Target=entity};
                  multipleRequest.Requests.Add(updateRequest);
                  }			
    
           // Execute all the requests in the request collection using a single web method call.
    ExecuteMultipleResponse multipleResponse = (ExecuteMultipleResponse)service.Execute(multipleRequest);
    }
    }

    Thanks

    Tuesday, November 11, 2014 9:59 PM

All replies

  • The overall approach looks fine, but I think you've an error on the following line:

    UpdateRequest updateRequest=new UpdateRequest{Target=entity};
    

    I don't know where 'entity' is defined by I think you should change it to:

    UpdateRequest updateRequest=new UpdateRequest{Target=item};
    


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Tuesday, November 11, 2014 10:47 PM
    Moderator
  • oh yes.. thank you. I changed it.

    I am registering this plugin on 'Merge' message. Can there be more than one plugin  for a message?

    Because there is one registered already for Merge message and I am seeing an error "Error registering plugins. Cannot insert duplicate keys.

    Sorry for being dumb, I am new to CRM and plugins.

    Thanks

    Wednesday, November 12, 2014 3:57 AM
  • bump..
    Wednesday, November 12, 2014 1:35 PM