简体   繁体   中英

Add value to lookup field in CRM dynamics 2011

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 ?

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM