缺少CRM插件的联系人PreImage中的字段

时间:2012-03-14 05:37:42

标签: .net plugins dynamics-crm-2011 crm

我正在尝试将来自CRM服务器的数据同步回单独的服务,并通过CRM插件进行此操作。这适用于大多数情况,但是在Contact实体上的Update Event上我遇到了问题。

外部服务要求同时同步所有字段,但更新事件仅提供已更改的字段,因此我为Contact事件添加了PreImage。 as detailed here

这提供了联系实体的一些字段,但仍有一些字段丢失。通过指向AddressID的链接删除地址字段,但联系实体中仍有一些字段似乎没有提供给插件。

称呼,电子邮件1,电话1字段似乎都缺失了。这些字段列在插件注册工具的preImage UI中,但它们没有显示在提供给代码的内容中。

如何访问它们?

<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>

1 个答案:

答案 0 :(得分:1)

看似缺少的字段是否有值?如果未填充字段(例如,具有空值),则它们将不是图像属性集合的一部分。如果是这种情况,那么您可能希望在使用以下内容查询之前检查它们的存在: -

if(!preImage.Attributes.Contains("myAttributeName"))
{

}

如果情况并非如此,那么也许您可以发布更多关于触发插件的实体的详细信息,以便我可以了解此处查询的数据。

感谢。