Reputation: 23
I'm trying to sync data from a CRM server back to a separate service, and am going about this via a CRM Plugin. This works for most cases but on the Update Event on a Contact entity I'm running into issues.
The external service requires all fields to be synced at the same time, but the update event only supplies the changed fields, so I add a PreImage for the Contact event. as detailed here
This provides the some of the fields for the Contact Entity but some are still missing. Address fields are removed with a link to an AddressID, but there are still fields in the Contact Entity which don't seem to be supplied to the plugin.
The salutation, email1, telephone1 fields all appear to missing. The fields are listed in the plugin registration tool's preImage UI, but they're not showing up in what's supplied to the code.
How do I go about accessing them?
<PreEntityImages xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
<a:KeyValuePairOfstringEntitygUGIFE1S>
<b:key>UpdateContactPreImage</b:key>
<b:value>
<a:Attributes>
<a:KeyValuePairOfstringanyType>
<b:key>customertypecode</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>1</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>mobilephone</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:string">mobile</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>merged</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:boolean">false</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>territorycode</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>1</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>haschildrencode</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>1</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>exchangerate</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:decimal">1.0000000000</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>preferredappointmenttimecode</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>1</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>address2_addresstypecode</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>1</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>isbackofficecustomer</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:boolean">false</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>owningbusinessunit</b:key>
<b:value i:type="a:EntityReference">
<a:Id>250293c1-99fe-e011-b93d-0019b9f1ed44</a:Id>
<a:LogicalName>businessunit</a:LogicalName>
<a:Name i:nil="true"/>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>owninguser</b:key>
<b:value i:type="a:EntityReference">
<a:Id>081693c1-99fe-e011-b93d-0019b9f1ed44</a:Id>
<a:LogicalName>systemuser</a:LogicalName>
<a:Name i:nil="true"/>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>lastname</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:string">[test] Last Name</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>donotpostalmail</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:boolean">false</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>donotphone</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:boolean">false</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>preferredcontactmethodcode</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>1</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>educationcode</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>1</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>ownerid</b:key>
<b:value i:type="a:EntityReference">
<a:Id>081693c1-99fe-e011-b93d-0019b9f1ed44</a:Id>
<a:LogicalName>systemuser</a:LogicalName>
<a:Name>System Administrator</a:Name>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>customersizecode</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>1</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>firstname</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:string">[test] First Name 14/03/2012 9:56:54 AM</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>yomifullname</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:string">
[test] First Name 14/03/2012 9:56:54 AM [test] Last Name
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>address2_shippingmethodcode</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>1</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>donotemail</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:boolean">false</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>fullname</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:string">
[test] First Name 14/03/2012 9:56:54 AM [test] Last Name
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>address1_addressid</b:key>
<b:value xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/" i:type="c:guid">f1091577-68ca-4e47-8af0-062433964799</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>address2_freighttermscode</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>1</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>statuscode</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>1</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>createdon</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:dateTime">2012-02-20T05:02:03Z</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>donotsendmm</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:boolean">false</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>donotfax</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:boolean">false</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>leadsourcecode</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>1</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>address1_country</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:string">0</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>creditonhold</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:boolean">false</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>telephone2</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:string">homephone</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>shippingmethodcode</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>1</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>telephone1</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:string">businessphone</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>transactioncurrencyid</b:key>
<b:value i:type="a:EntityReference">
<a:Id>c5d4dc22-9afe-e011-b93d-0019b9f1ed44</a:Id>
<a:LogicalName>transactioncurrency</a:LogicalName>
<a:Name>Australian Dollar</a:Name>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>donotbulkemail</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:boolean">false</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>modifiedby</b:key>
<b:value i:type="a:EntityReference">
<a:Id>081693c1-99fe-e011-b93d-0019b9f1ed44</a:Id>
<a:LogicalName>systemuser</a:LogicalName>
<a:Name>System Administrator</a:Name>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>createdby</b:key>
<b:value i:type="a:EntityReference">
<a:Id>081693c1-99fe-e011-b93d-0019b9f1ed44</a:Id>
<a:LogicalName>systemuser</a:LogicalName>
<a:Name>System Administrator</a:Name>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>contactid</b:key>
<b:value xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/" i:type="c:guid">e5f28440-7f5b-e111-b93d-0019b9f1ed44</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>modifiedon</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:dateTime">2012-03-13T23:56:55Z</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>participatesinworkflow</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:boolean">false</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>statecode</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>0</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>address2_addressid</b:key>
<b:value xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/" i:type="c:guid">6c3024e7-5eba-4394-9192-e7106db17c0e</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>donotbulkpostalmail</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:boolean">false</b:value>
</a:KeyValuePairOfstringanyType>
</a:Attributes>
<a:EntityState i:nil="true"/>
<a:FormattedValues>
<a:KeyValuePairOfstringstring>
<b:key>customertypecode</b:key>
<b:value>Default Value</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>merged</b:key>
<b:value>No</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>territorycode</b:key>
<b:value>Default Value</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>haschildrencode</b:key>
<b:value>Default Value</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>exchangerate</b:key>
<b:value>1.0000000000</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>preferredappointmenttimecode</b:key>
<b:value>Morning</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>address2_addresstypecode</b:key>
<b:value>Default Value</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>isbackofficecustomer</b:key>
<b:value>No</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>donotpostalmail</b:key>
<b:value>Allow</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>donotphone</b:key>
<b:value>Allow</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>preferredcontactmethodcode</b:key>
<b:value>Any</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>educationcode</b:key>
<b:value>Default Value</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>customersizecode</b:key>
<b:value>Default Value</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>address2_shippingmethodcode</b:key>
<b:value>Default Value</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>donotemail</b:key>
<b:value>Allow</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>address2_freighttermscode</b:key>
<b:value>Default Value</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>statuscode</b:key>
<b:value>Active</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>createdon</b:key>
<b:value>2012-02-20T15:02:03+10:00</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>donotsendmm</b:key>
<b:value>Send</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>donotfax</b:key>
<b:value>Allow</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>leadsourcecode</b:key>
<b:value>Default Value</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>creditonhold</b:key>
<b:value>No</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>shippingmethodcode</b:key>
<b:value>Default Value</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>donotbulkemail</b:key>
<b:value>Allow</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>modifiedon</b:key>
<b:value>2012-03-14T09:56:55+10:00</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>participatesinworkflow</b:key>
<b:value>No</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>statecode</b:key>
<b:value>Active</b:value>
</a:KeyValuePairOfstringstring>
<a:KeyValuePairOfstringstring>
<b:key>donotbulkpostalmail</b:key>
<b:value>No</b:value>
</a:KeyValuePairOfstringstring>
</a:FormattedValues>
<a:Id>e5f28440-7f5b-e111-b93d-0019b9f1ed44</a:Id>
<a:LogicalName>contact</a:LogicalName>
<a:RelatedEntities/>
</b:value>
</a:KeyValuePairOfstringEntitygUGIFE1S>
</PreEntityImages>
Upvotes: 2
Views: 2655
Reputation: 637
Do the fields which appear to be missing have a value? If the fields are not populated (e.g. Have a null value) then they will not be part of the image attribute collection. If that is the case then you will likely want to check for their presence before query them with something like:-
if(!preImage.Attributes.Contains("myAttributeName"))
{
}
If that is not the case, then perhaps you could post some more details of the entity which is firing the plug in so I can get an idea of the data being queried here.
Thanks.
Upvotes: 1