0

This is a compact version, please ask if you need clarifications:

I have managed to register an endpoint so that when I update a property (for example phone number) in Dynamics CRM Online a message is sent to Azure Service Bus (topic and/or queue, no difference here). I also have a webjob that listens to theses changes, using the signature below:

public static void ProcessTopicMessage([ServiceBusTrigger("my-crm-topic", "topic-subscription1" )] BrokeredMessage pQueueItem, TextWriter log)
{
   RemoteExecutionContext package = pQueueItem.GetBody<RemoteExecutionContext>();

   if(package.MessageName == "Update")
   {
      Entity entity = pPackage.InputParameters["Target"] as Entity;            
      var newPhone = entity.GetAttributeValue<string("telephone1");    

   }        
}

This works ok, when I change for example phone number I can read the new phone number and all other properties are null. HOWEVER, I cant find any information on the name/id of the property/properties that were changed (except that they are not null).

I could loop through all property names and be happy with that, but the main problem is that there no way to know if the property was set back to null from something else.

I cannot find any indication of that its the phone number that has been changed in pQueueItem- or package-properties. Where do I find it?

Cowborg
  • 2,645
  • 3
  • 34
  • 51

3 Answers3

1

I took a shot at replicated what you are doing as I've never captured update, just create messages.

I captured the raw JSON that is put out and as you state when I add a phone number to a previously blank field for a contact I see only the new value and the message includes only the updated fields. Nothing else comes across.

When I delete the value, I basically get the same JSON. Only the change field with the new value of "" or empty string. The same rules seem to hold.

See Telephone1 below. Based on this experiment, you could loop through the properties as you say... if it is there, it has been changed to the current value in the field.

Thanks, Joe.

"InputParameters": [
{
  "key": "Target",
  "value": {
    "__type": "Entity:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
    "Attributes": [
      {
        "key": "telephone1",
        "value": ""
      },
      {
        "key": "contactid",
        "value": "c50fe891-a0f0-e611-8120-c4346b"
      },
      {
        "key": "modifiedon",
        "value": "\/Date(1487772895000)\/"
      },
      {
        "key": "modifiedby",
        "value": {
          "__type": "EntityReference:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
          "Id": "6343f538-cde0-48ba-b249-b67ec24e765a",
          "KeyAttributes": [

          ],
          "LogicalName": "systemuser",
          "Name": null,
          "RowVersion": null
        }
      },
      {
        "key": "modifiedonbehalfby",
        "value": null
      }
    ],
    "EntityState": null,
    "FormattedValues": [

    ],
    "Id": "c50fe891-a0f0-e611-8120-c4346bb5984c",
    "KeyAttributes": [

    ],
    "LogicalName": "contact",
    "RelatedEntities": [

    ],
    "RowVersion": null
  }
}
Joe
  • 61
  • 1
0

I have managed to register an endpoint so that when I update a property (for example phone number) in Dynamics CRM Online a message is sent to Azure Service Bus (topic and/or queue, no difference here). I also have a webjob that listens to theses changes

If you’d like to retrieve properties of message entity that has updated property in your WebJobs, you could try to set additional custom property to BrokeredMessage object that indicates if properties of current message entity is updated.

BrokeredMessage message = new BrokeredMessage(mes);
message.Properties["isupdated"] = 1;

and then you could create filter for your topic subscription to restrict only message with isupdated > 0 could be passed to this topic subscription’s virtual queue. In this way, you could create a WebJob to process messages that are passed to this specific topic subscription to handle the updated message entity.

Fei Han
  • 26,415
  • 1
  • 30
  • 41
  • The issue is with determining that there was an update. Brokered message is coming from CRM. It's more of the Dynamics issue that poorly communicates entity changes. – Sean Feldman Feb 22 '17 at 14:48
0

Got the answer from another forum Basically, check entity.Attributes-array (see code in question). The 4 last ones are always there on update, the n first are name/newvalue of properties that was changed.

Cowborg
  • 2,645
  • 3
  • 34
  • 51