简体   繁体   中英

How do I read an attribute below in CRM 2011 using javascript?

I am looking for the most simplest way of writing javascript code to read an attribute(s) from the fetch xml given below. I have bumped into very complex ways of doing it. Can you suggest a quick and efficient way of doing it.

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
    <entity name="bch_delegate">
        <attribute name="bch_delegateid" />
        <attribute name="bch_name" />
        <attribute name="createdon" />
        <order attribute="bch_name" descending="false" />
        <filter type="and">
            <condition attribute="bch_signingauthority" operator="eq" uiname="Randy Claire" uitype="bch_signingauthority" value="{F391B13B-37ED-E411-AD95-0050569148C9}" />
        </filter>
    </entity>
</fetch>

Easiest way to to this is to use the XrmServiceToolkit from Codeplex. Sample see here How use XRM Service Toolkit

I would use jQuery (keep in mind that jQuery 2.+ doesn't work with IE8, so I would use a 1.* version above 1.7). Here's an example:

//outer loop  
$(xml).find("a\\:Entity").each(function() {  
//inner loop  
$(this).find("a\\:KeyValuePairOfstringstring").each(function() {  
var xmlElement = $(this);  
var key = xmlElement.find("b\\:key").text();  
var value = xmlElement.find("b\\:value").text();  
//do something with the key and value  
});  

Hopefully this helps. Here's the site it was found on: http://alexanderdevelopment.net/post/2013/01/21/fetchxml-jquery-in-a-dynamics-crm-2011-web-resource/

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