You receive an "Error in action posturl" message when a Workflow Rule is run while going back Online in the Microsoft CRM Sales for Outlook Client (878435)



The information in this article applies to:

  • Microsoft CRM 1.2
  • Microsoft Business Solutions CRM 1.0

SYMPTOMS

A workflow rule has been created and implemented in Workflow Manager to respond to the create event of the Opportunity object in Microsoft CRM. When an Opportunity is created, the Post Url action is used to send the opportunityid, createdby, and owningbusinessunit to a custom WebService. The WebService has a function that uses the CRMQuery.ExecuteQuery method to retrieve the value of a custom field used to track a custom quote number, CFSQuoteNum. The highest CFSQuoteNum is determined and incremented by 1. Then the CRMOpportunity.Update method is used to update the current Opportunity with the appropriate custom quote number.

The workflow rule works fine when implemented via the Microsoft CRM Web Client and while online with the Microsoft CRM Sales for Outlook client. However, if multiple opportunities are created while offline in the Microsoft CRM Sales for Outlook Client, the following error is returned in the Workflow Monitor for some, not all, of the Opportunities that were created offline:

<description>Error in action posturl.</description><details>Failed to connect the url http://localhost/WebService1.asmx/Service1.asmx/UpdateQuoteNum?</details><file>c:\crm\seteam\src\platform\workflow\service\processengine.inl</file><line>5228</line>

CAUSE

Multiple threads produced by the opportunities created offline are causing synchronization issues. One thread is interrupting what another thread is doing, thus leaving the object in an invalid state. Specifically, accessing the same database table at the same time to retrieve the CFSQuoteNum causes the CRMQuery.ExecuteQuery to throw an exception resulting in the error described in the Symptoms section

RESOLUTION

This problem can be solved through correct synchronization of the multiple threads. The multiple instances of the web service need to be synchronized using the .Net framework. A Mutex can be used to synchronize access to an object or to build a low level synchronization mechanism. Using a Mutex we have a way to anchor all synchronization around a single named mutex, which will be shared across all objects, threads and even processes.

To utilized a Mutex in this scenario:

1. Include System.Threading

using System.Threading;

2. Create a new named mutex.

private static Mutex mutex = new Mutex(false,"Service1.asmx.Mutex");

3. In the beginning of the function that retrieves the CRM data using the CRMQuery.ExecuteQuery and updates the Opportunity using the CRMOpportunity.Update method, wait for the mutex.

mutex.WaitOne();

4. In the end of the function, release the mutex.

finally
{
mutex.ReleaseMutex();
}

REFERENCES

For additional information on the use of Mutexes:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconmutex.asp

For additional information on Threading:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconthreading.asp

For additional information on the CRMQuery.ExecuteQuery Method:
Version 1.0: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/CrmSdk/htm/crmqueryexecutequerymethod.asp
Version 1.2: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/CrmSdk1_2/htm/v1d2crmqueryexecutequerymethod.asp

For additional information on the CRMOpportunity.Update Method:
Version 1.0: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/CrmSdk/htm/crmopportunityupdatemethod.asp
Version 1.2: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/CrmSdk1_2/htm/v1d2crmopportunityupdatemethod.asp

This article was TechKnowledge Document ID: 35454

Modification Type:MinorLast Reviewed:8/5/2005
Keywords:kbMBSworkflow kbMBSMigrate KB878435 kbAudEndUser