Add value to lookup field in CRM dynamics 2011

若如初见. 提交于 2019-12-24 12:37:55

问题


I managed to make a successful online connection using PHP to the CRM dynamics 2011. I even managed to create a new lead and add the following presented values:

<s:Body>
                <Create xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
                <entity xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                    <b:Attributes xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
                        <b:KeyValuePairOfstringanyType>
                            <c:key>name</c:key>
                            <c:value i:type="d:string" xmlns:d="http://www.w3.org/2001/XMLSchema">Test Here</c:value>
                        </b:KeyValuePairOfstringanyType>
                        <b:KeyValuePairOfstringanyType>
                            <c:key>emailaddress1</c:key>
                            <c:value i:type="d:string" xmlns:d="http://www.w3.org/2001/XMLSchema">test@test.com</c:value>
                        </b:KeyValuePairOfstringanyType>
                        <b:KeyValuePairOfstringanyType>
                            <c:key>address1_city</c:key>
                            <c:value i:type="d:string" xmlns:d="http://www.w3.org/2001/XMLSchema">Location Here</c:value>
                        </b:KeyValuePairOfstringanyType>
                        <b:KeyValuePairOfstringanyType>
                            <c:key>telephone1</c:key>
                            <c:value i:type="d:string" xmlns:d="http://www.w3.org/2001/XMLSchema">123456</c:value>
                        </b:KeyValuePairOfstringanyType>
                    </b:Attributes>
                    <b:EntityState i:nil="true"/>
                    <b:FormattedValues xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
                    <b:Id>00000000-0000-0000-0000-000000000000</b:Id>
                    <b:LogicalName>account</b:LogicalName>
                    <b:RelatedEntities xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
                </entity>
                </Create>
            </s:Body>

The thing i'm stuck at now is how to add a value to lookup field "primarycontactid"

let's say for example I want to add the value of "Mahmoud Jabado"

I have red that there is a javascript function, I was just a little lost on where and how to implement it. isn't there a way to set the value in a similar way like the above XML ?

P.S: I am programing in PHP and my programing level is not high that much. Thanks everyone in advance.


回答1:


There is a way to set this directly in the xml, but you need the Guid of the contact you're trying to add. Something similar to the following worked for me in an old java application I worked on some time ago so should work for you too:

<b:KeyValuePairOfstringanyType>
    <c:key>primarycontactid</c:key>
    <c:value i:type="b:EntityReference">
        <b:Id>[CONTACT GUID GOES HERE]</b:Id>
        <b:LogicalName>contact</b:LogicalName>
        <b:Name i:nil="true" />
    </c:value>
</b:KeyValuePairOfstringanyType>

For <b:Name> you could put the contact name in there, but it shouldn't be required if you're creating/updating a record.

(Note: I have guessed the namespaces so it may need a bit of tweaking)



来源:https://stackoverflow.com/questions/15786840/add-value-to-lookup-field-in-crm-dynamics-2011

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!