Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

CRM SDK - Execute Multiple Response Failure

Posted on by Microsoft Employee

Hi,

Flow of email activity creation, attachment creation, and activity close:

  • Create email activity
  • Create email attachments while referencing above email id
  • Close email activity

Problem:

  • We are trying to use the ExecuteMultipleResponse request to create the email attachments, and it's saying that the created email id does not exist.

Question:

  • Have you experienced a similar problem with ExecuteMultipleResponse?

Code:

                emailActivityId = service.Create(emailActivity);

                //create attachments
                if (attachments != null)
                {
                    ExecuteMultipleRequest requestWithResults = new ExecuteMultipleRequest()
                    {
                        Settings = new ExecuteMultipleSettings()
                        {
                            ContinueOnError = false,
                            ReturnResponses = true
                        },
                        // Create an empty organization request collection.
                        Requests = new OrganizationRequestCollection()
                    };

                    foreach (Entity attachment in attachments)
                    {
                        attachment["objectid"] = new EntityReference("email", emailActivityId);
                        attachment["objecttypecode"] = "email";
                        //CreateRequest createRequest = new CreateRequest { Target = attachment };
                        //requestWithResults.Requests.Add(createRequest);
                        try
                        {
                            service.Create(attachment);
                        }
                        catch(Exception ex)
                        {
                            ErrorHandler.SendErrorMessage(typeof(PublicFunctions).Name, MethodBase.GetCurrentMethod().Name, $"Failure to CREATE ActivityMimeAttachment entity", ex);
                        }
                    }

                    //ExecuteMultipleResponse responseWithResults = (ExecuteMultipleResponse)service.Execute(requestWithResults);

                    //foreach (var responseItem in responseWithResults.Responses)
                    //{
                    //    if (responseItem.Fault != null)
                    //    {
                    //        ErrorHandler.SendErrorMessage(typeof(PublicFunctions).Name, MethodBase.GetCurrentMethod().Name, $"Failure to CREATE ActivityMimeAttachment entity", new Exception(responseItem.Fault.Message));
                    //    }
                    //}
                }

                //close activity
                var setEmailStateReq = new SetStateRequest
                {
                    EntityMoniker = new EntityReference("email", emailActivityId),
                    State = new OptionSetValue(1),
                    Status = new OptionSetValue(2) //Completed
                };
                service.Execute(setEmailStateReq);


Thank you for taking your time to respond!

*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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans