• CRM2011 读取fetch 查询返回的xml


    View Code
    View Code
    /*
    *根据属性名称读取属性值
    */
    function GetAttributeValue(entityNode, attrName) {
    
        var attributes = entityNode.selectNodes('//a:KeyValuePairOfstringanyType')
        for (var i = 0; i < attributes.length; i++) {
            var key = attributes[i].selectSingleNode('b:key').text;
            if (key == attrName) {
                var attribute = attributes[i];
                var itype = attribute.selectSingleNode('b:value').getAttribute('i:type')
                switch (itype) {
                    case 'a:EntityReference':
                        return {
                            Id: attribute.selectSingleNode('b:value/a:Id').text,
                            LogicalName: attribute.selectSingleNode('b:value/a:LogicalName').text,
                            Name: attribute.selectSingleNode('b:value/a:Name').text
                        };
                        break;
                    case 'a:OptionSetValue':
                        return {
    
                            Value: attribute.selectSingleNode('//a:Value').text
                        };
                        break;
                    default:
    
                }
            }
    
        }
    }

     昨天测试完后对代码做了一些调整,补充一些default

    /*
    *根据属性名称读取属性值
    */
    function GetAttributeValue(entityNode, attrName) {
    
        var attributes = entityNode.selectNodes('//a:KeyValuePairOfstringanyType')
        for (var i = 0; i < attributes.length; i++) {
            var key = attributes[i].selectSingleNode('b:key').text;
            if (key == attrName) {
                var attribute = attributes[i];
                var itype = attribute.selectSingleNode('b:value').getAttribute('i:type')
                switch (itype) {
                    case 'a:EntityReference':
                        return {
                            Id: attribute.selectSingleNode('b:value/a:Id').text,
                            LogicalName: attribute.selectSingleNode('b:value/a:LogicalName').text,
                            Name: attribute.selectSingleNode('b:value/a:Name').text
                        };
                        break;
                    case 'a:OptionSetValue':
                        return {
    
                            Value: attribute.selectSingleNode('//a:Value').text
                        };
                        break;
                    default:
                        return attribute.selectSingleNode('b:value').text;
                        break;
    
    
                }
            }
    
        }
    }
    <a:Entity xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
    <a:Attributes xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
    <a:KeyValuePairOfstringanyType>
    <b:key>new_backupid</b:key>
    <b:value xmlns:i="http://www.w3.org/2001/XMLSchema-instance" i:type="c:guid" xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/">e27f1c40-7ffc-e111-90d0-00155d77394d</b:value>
    </a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>new_account_new_backup_id</b:key><b:value xmlns:i="http://www.w3.org/2001/XMLSchema-instance" i:type="a:EntityReference"><a:Id>091d12c9-cec4-e111-ab5c-00155d77394d</a:Id><a:LogicalName>account</a:LogicalName><a:Name>ACE Life Insurance Company Limited</a:Name></b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>new_type</b:key><b:value xmlns:i="http://www.w3.org/2001/XMLSchema-instance" i:type="a:OptionSetValue"><a:Value>100000000</a:Value></b:value></a:KeyValuePairOfstringanyType>
    <a:KeyValuePairOfstringanyType><b:key>new_systemuser_new_backup_id</b:key><b:value xmlns:i="http://www.w3.org/2001/XMLSchema-instance" i:type="a:EntityReference"><a:Id>a0534b18-b5c4-e111-ab5c-00155d77394d</a:Id><a:LogicalName>systemuser</a:LogicalName><a:Name>方力</a:Name></b:value></a:KeyValuePairOfstringanyType></a:Attributes><a:EntityState xmlns:i="http://www.w3.org/2001/XMLSchema-instance" i:nil="true"/><a:FormattedValues xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic"><a:KeyValuePairOfstringstring>
    <b:key>new_type</b:key><b:value>临分个险核保A</b:value></a:KeyValuePairOfstringstring></a:FormattedValues><a:Id>e27f1c40-7ffc-e111-90d0-00155d77394d</a:Id>
    <a:LogicalName>new_backup</a:LogicalName>
    <a:RelatedEntities xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
    </a:Entity>
  • 相关阅读:
    实例图解SQL SERVER2000使用AWE进行内存优化
    使用Power Designer正反向数据库及生成设计报告
    使用SVN+CruiseControl+ANT实现持续集成之二环境搭建和配置介绍
    使用SVN+CruiseControl+ANT实现持续集成之三构建操作及监视
    【排序】排序算法之分配排序
    [Cocoa]自定义TableViewCell实现圆角/渐变色TableView
    [Cocoa]XCode 3.2 常用快捷键
    [Cocoa]实现了一套自定义动画库
    Vim 使用入门快捷键
    [Cocoa] iPhone/iPad 时区转换
  • 原文地址:https://www.cnblogs.com/hellohongfu/p/2681817.html
Copyright © 2020-2023  润新知