Tuesday, March 31, 2015

How to create a message in a Scribe Insight queue using C#

If you are familiar with Scribe Insight then you would know that “queue” based integration is the preferred integration method. The reason for that is performance. Multiple message processors can be allocated to process the queues. For more information please read this blog on the “Message Processor”.

Scribe Adapters can create the queue message automatically, but, what if we need to create the queue message from the portal or a custom program? This blog will show you how to create a MSMQ message using C#.

The code below will create a message with the label "PortalCustomer" and put it in the ScribeIn queue.

using System;
using System.Messaging;

namespace MSMQ
    class Program
        static void Main(string[] args)
            Console.WriteLine("Initiating MSMQ object");
           // queue address
            string queueAddress = @"FormatName:Direct=OS:machinename\private$\scribein";
            Console.WriteLine("Queue Path: {0}", queueAddress);

            //Create an instance of MSMQ Manager
            MSMQManager msmq = new MSMQManager(queueAddress);

            Console.WriteLine("Message sent successfully");

    // Class that initiate the message queue and send the message
    class MSMQManager
        private string queueAddress;

        public MSMQManager(string queueAddress)
            this.queueAddress = queueAddress;

        //Creating and sending the message
        public void SendMessageToQueue()
            MessageQueue msMq = new MessageQueue(queueAddress);

               //create an instance of customer class
                Customer req = new Customer()

                Console.WriteLine("Creating customer request: {0}", req.ToString());

                //create the message
                Message m = new Message()
                    Body = req,
                    Label = "PortalCustomer",
                    Recoverable = true,
                Console.WriteLine("Initialising message: {0}", m.Label);


            catch (MessageQueueException e)
            catch (Exception e)
                Console.Write("Error Message: {0}. Trace: {1}", e.Message, e.StackTrace);
Here is the code for the customer class.

using System;

namespace MSMQ
    public class Customer
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public DateTime ReceivedDate { get; set; }

        public override string ToString()
            return string.Format("Link: {0} - Response: {1} - ReceivedDate: {2}", FirstName, LastName , ReceivedDate.ToString());

Run the code and look in the ScribeIn queue or in the Dead Message queue (if you don’t have any integration using label “PortalCustomer”).


Make sure that MSMQ are installed on the machine where the code is hosted, and can communicate  with Scribe server on port 1801.

Thursday, February 5, 2015

Microsoft CRM publisher stuck on “Initializing” in Scribe Insight

If you are trying to create a CRM publisher in Scribe Insight and it is stuck on “Initializing” as shown in the screen shot below:
It means that there is something wrong.


If you check in the event viewer, you may find the following error:
An unexpected error occurred.
Microsoft Dynamics CRM Publisher
Error setting publisher settings: System.Messaging.MessageQueueException (0x80004005): Invalid queue path name.
   at System.Messaging.MessageQueue.ResolveFormatNameFromQueuePath(String queuePath, Boolean throwException)
   at System.Messaging.MessageQueue.Exists(String path)
   at Scribe.AdapterBase.Publisher.QueueService.InitPublisherQueues(String pubInQueueName, String pubSucceededQueueName, String pubFailedQueueName)
   at Scribe.AdapterBase.Publisher.ScribePubWorkerBase.InitPublisherQueues()
   at Scribe.AdapterBase.Publisher.ScribePubWorkerBase.setSettings(String settingsXML, String entitiesXML, Object lastRunTime, Object lastRunTimeUTC)
The error suggests that there is problem with the path of the queue


Compare the queue names in the CRM publisher and message queues in component services as shown in the following screen shots.
image image
If the queue names are different then we have to update the queue names in the internal database.
Note: I don’t know if this is a supported solution.
  1. Backup your ScribeInternal database.
  2. Look into the scribe.bridges table and find the bridgeid of your CRM publisher. All the publisher settings including the queues are stored in the settings column.
  3. Now update the settings column with the proper queue paths.
Note: Settings column stores the data as XML. Please be careful when updating the column.

Wednesday, January 28, 2015

'Security Negotiation Exception' during plug-in execution in CRM2013

A few months ago, we experienced an issue during a plugin execution in the dev. environment. We were using Scribe Insight for integration. We were using the “Microsoft Dynamics CRM publisher” for scribe that registered a plugin on the contact entity. Everything was working perfectly until we received the following error:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: The following error has occurred in the Scribe Change History plug-in: System.ServiceModel.Security.SecurityNegotiationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #0CCC3255  


During troubleshooting we found the following entry in the event viewer of the backend server. 

The Kerberos client received a KRB_AP_ERR_MODIFIED error from the server serviceaccountname. The target name used was HTTP/CRMFrontEndServer. This indicates that the target server failed to decrypt the ticket provided by the client. This can occur when the target server principal name (SPN) is registered on an account other than the account the target service is using. Ensure that the target SPN is only registered on the account used by the server. This error can also happen if the target service account password is different than what is configured on the Kerberos Key Distribution Center for that target service. Ensure that the service on the server and the KDC are both configured to use the same password. If the server name is not fully qualified, and the target domain (DomainName) is different from the client domain (DomainName), check if there are identically named server accounts in these two domains, or use the fully-qualified name to identify the server 

The “EventSourceName” was Kerberos.

Looking at the error we hypothesised that there was an SPN issue for the CRMFrontEndServer server.

You can receive this error for any plugin published in the sandbox. It will only happen if the sandbox service is not installed on the same server as CRM web site and kerberos authentication is enabled for the website.


We used the following account to list all the SPNs registered for the serviceaccountname.
setspn –l domain\serviceaccountname

The command displays only the SPN registered on the HTTP/CRMfrontEndServer.CRM.domainname.com  (Fully Qualified domain name of the CRM front end server).

We added a new SPN on the servername using the following command setspn –a http/CRMFrontEndServer domain\serviceaccountname That was it. We restarted the sandbox service and the error was gone.

For more information on SPNs and their configuration you can check out this KB article from Microsoft. http://support.microsoft.com/kb/929650 

Wednesday, December 3, 2014

Strange behaviour of the two options(Boolean) field in CRM2013

Last week, I came across a strange behaviour of the two options field in CRM2013. I am not sure if it is a bug or it is by design.


I have a boolean field on an entity. This field is not added to the form. The default value of the field is set to false. When a new record is created in CRM, the integration process copies the record into the external system and updates the boolean field to true in the CRM. This boolean field indicates if the record is copied to the external system or not.

It works perfectly expect in the following scenario.

If the user updates the  record immediately after creating the record without closing the form, CRM will reset the value of the boolean field back to false. According to me, it is a bug. CRM should not pass the un modified fields to the save method.

The following screen shot displays the audit history of the field.



Add the field to the form.

Monday, November 24, 2014

InitializeFromRequest in CRM2013

InitializeFromRequest may be the least used request in the Dynamics CRM. It is available since CRM 4.0. I was talking to some of the guys in my team and most of them have never used this request. It initiates an instance of an entity from an existing entity.

It can be used when there is a 1:N relationship between the entities. It is equivalent of creating a child record from the parent form.

For example there is a 1:N relationship between account and contact. if you create a contact from the contact subgrid from the account form, it will prefill the parentcustomer field and all the fields defined in the relationship mappings.

The following screen shot displays the mappings of 1:N relationship between account and contact.
The same functionality can be achieved using InitializeFromRequest. This request returns a InitializeFromResponse. The request does not create a new record but the response can be used to create a new record.
Here is the code.
    // Create the request object
     InitializeFromRequest initialize = new InitializeFromRequest();

     // Set the properties of the request object
     initialize.TargetEntityName = "contact";

     // Create the EntityMoniker
     initialize.EntityMoniker = new EntityReference("account", new Guid("8A5D8108-DE3B-E311-9401-00155D1B7B00"));
     // fields to initialised from parent entity
     initialize.TargetFieldType = TargetFieldType.All;

     // Execute the request
     InitializeFromResponse initialized =

     if (initialized.Entity != null)
         //get entity from the response
         Entity entity = initialized.Entity;

         // set the name for the contact
         entity.Attributes.Add("firstname", "John");
         entity.Attributes.Add("lastname", "Smith");

         //create a new contact

Happy coding..

Saturday, August 9, 2014

Setup and Deployment guide for ‘Performance Toolkit’ for Dynamics CRM 2011

Performance Toolkit for Microsoft Dynamics CRM 2011 is available on ‘Microsoft Pinpoint’. But the hyperlink for ‘setup and deployment’ guide is not working. It always displays the following message.
service unavailable 

I have found an old copy of the guide. You can download the guide from here.


Friday, December 6, 2013

“Run Report” button on custom entities forms

In CRM2013 the “Run Report” button is missing on custom entities. The button is not available even if you have selected display in the “Forms of the related record types”. The problem is the “Display Rule” named “Mscrm.HideOnCommandBar” associated with the “Run Report” button. It is a default behaviour for custom entities.

There are 2 different ways to display the “Run Report” button on the custom entities.

By adding the "CommandDefinition” to the ribbon definition of the entity.

  1. Create a new solution in CRM, add contact entity to the solution and export the solution.
  2. Open the customization file from the exported solution and look for <RibbonDiffXML> . It will look like the following XML.
  3. <RibbonDiffXml>
      <CustomActions />
        <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
      <CommandDefinitions />
        <TabDisplayRules />
        <DisplayRules />
        <EnableRules />
      <LocLabels />
  4. Replace the highlighted line yellow with the following XML
  5. <CommandDefinition Id="Mscrm.ReportMenu.Form">
          <EnableRule Id="Mscrm.FormStateNotNew" />
          <DisplayRule Id="Mscrm.ReadReport" />
        <Actions />
  6. Save the file and overwrite the Customization file in your exported solution zip file with this file.
  7. Import the solution zip file and publish it. It’s done.

By using  Ribbon Work Bench 2013

Report button can be easily restored using “Ribbon Work Bench 2013”. Check http://community.dynamics.com/crm/b/develop1/archive/2013/09/06/how-to-restore-a-hidden-button-on-the-crm-2013-command-bar.aspx for the step by step instructions.
Note: Make sure in the step 4 of the instructions,  “Form” is selected in the upper right corner as shown in the following screen shot.