Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to manage multiple crm 2011 workflows async calls?
    text
    copied!<p>I'm trying to build a custom workflow that inserts contacts or account into a marketing list. So, it works perfectly except when i try to make multiple calls. In that case, I notice that not every process complete with this error: </p> <blockquote> <p>Workflow paused due to error: Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: ValidateOpen - Encountered disposed CrmDbConnection when it should not be disposedDetail: <br> -2147220968 Message>ValidateOpen - Encountered disposed CrmDbConnection when it should not be disposed /Message><br> 2013-03-19T11:47:06.588342Z -2147220970 <p>Message>System.ObjectDisposedException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: FB9BF845 /Message</p> </blockquote> <pre class="lang-cs prettyprint-override"><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Workflow; using System.Activities; using System.IO; namespace ContactToMarketingList { public class ContactToMList : CodeActivity { protected override void Execute(CodeActivityContext executionContext) { try { new AddToList(executionContext, contact, MList, inserimento); } catch { } } [Input("Contatto")] [ReferenceTarget("contact")] public InArgument&lt;EntityReference&gt; contact { get; set; } [Input("Marketing List")] [ReferenceTarget("list")] public InArgument&lt;EntityReference&gt; MList { get; set; } [Input("Inserimento")] public InArgument&lt;bool&gt; inserimento { get; set; } bool action = false; private static IOrganizationService myService = null; private static string _separatore = "\r\n"; private static string fileName = "c:\\temp\\ContactToMList_logs.txt"; int count = 0; } public class AddToList { private static Guid _contactiId; private static Guid _listId; private static bool _insert = false; private static bool _action = false; private static IExecutionContext _executionContext = null; private static IOrganizationServiceFactory _organizationServiceFactory = null; private static IOrganizationService _service = null; public AddToList(CodeActivityContext executionContext, InArgument&lt;EntityReference&gt; contact, InArgument&lt;EntityReference&gt; MList, InArgument&lt;bool&gt; inserimento) { _executionContext = executionContext.GetExtension&lt;IExecutionContext&gt;(); _organizationServiceFactory = executionContext.GetExtension&lt;IOrganizationServiceFactory&gt;(); _service = _organizationServiceFactory.CreateOrganizationService(_executionContext.UserId); _contactiId = contact.Get&lt;EntityReference&gt;(executionContext).Id; _listId = MList.Get&lt;EntityReference&gt;(executionContext).Id; _insert = inserimento.Get&lt;bool&gt;(executionContext); _addtoList(); } private static void _addtoList() { XrmDataContext datacontext = new XrmDataContext(_service); var MyContact = (from c in datacontext.ContactSet where c.ContactId == _contactiId select c.Id).ToArray(); var MyList = (from l in datacontext.ListSet where l.Id == _listId select l).ToList().FirstOrDefault(); var members = (from m in datacontext.ListMemberSet where m.ListId.Id == MyList.ListId select m.EntityId.Id).ToArray(); foreach (Guid id in members) if (MyContact.FirstOrDefault() == id) _action = true; if (_insert &amp;&amp; !_action) { AddListMembersListRequest AddMemberRequest = new AddListMembersListRequest(); AddMemberRequest.ListId = _listId; AddMemberRequest.MemberIds = MyContact; AddListMembersListResponse AddMemberResponse = _service.Execute(AddMemberRequest) as AddListMembersListResponse; } else if (!_insert &amp;&amp; _action) { // File.AppendAllText(fileName, "Remove contact to list - INIZIO"+_separatore); RemoveMemberListRequest RemoveMemberRequest = new RemoveMemberListRequest(); RemoveMemberRequest.ListId = _listId; RemoveMemberRequest.EntityId = MyContact.FirstOrDefault(); // Use AddListMembersListReponse to get information about the request execution RemoveMemberListResponse RemoveMemberResponse = _service.Execute(RemoveMemberRequest) as RemoveMemberListResponse; // service.Update(MyList); // File.AppendAllText(fileName, "Remove contact to list - FINE"+_separatore); } else { // File.AppendAllText(fileName, insert == true ? "L'utente è già presente nella Lista di Marketing." +_separatore: "L'utente non è presente nella Lista di Marketing." +_separatore); } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload