【问题标题】:CRM 2011: Insert condition to a fetchXML query using javascriptCRM 2011:使用 javascript 向 fetchXML 查询插入条件
【发布时间】:2013-05-19 11:08:09
【问题描述】:

我有以下获取 XML 查询:

<fetch mapping="logical">
    <entity name="salesorder">
        <attribute name="salesorderid"/>
        <attribute name="new_type"/>
        <attribute name="new_solomonswonumber"/>
        <attribute name="new_resolutioncode"/>
        <attribute name="new_rentalsaleindicator"/>
        <attribute name="new_preferredphone"/>
        <attribute name="name"/>
        <attribute name="new_equipment"/>
        <attribute name="customerid"/>
        <order attribute="new_type" descending="false"/>
        <filter type="and">
            <condition attribute="salesorderid" operator="eq" value="5AC5CBAC-25A0-E211-92B3-00155D815016"/></filter>
        <link-entity name="new_entity" from="new_entityid" to="new_entitylookup">
            <filter type="and">
                <attribute name="new_street1"/>
                <attribute name="new_province"/>
                <attribute name="new_postalcode"/>
                <attribute name="new_city"/>
            </filter>
        </link-entity>
    </entity></fetch>

我有一个业务需要,我需要使用 java 脚本插入以下条件:

<condition attribute='new_entityid' operator='eq' value='10ad18f6-c384-e211-b04d-78e3b50834b8'/>

这样最终的fetchxml如下:

<fetch mapping="logical">
    <entity name="salesorder">
        <attribute name="salesorderid"/>
        <attribute name="new_type"/>
        <attribute name="new_solomonswonumber"/>
        <attribute name="new_resolutioncode"/>
        <attribute name="new_rentalsaleindicator"/>
        <attribute name="new_preferredphone"/>
        <attribute name="name"/>
        <attribute name="new_equipment"/>
        <attribute name="customerid"/>
        <order attribute="new_type" descending="false"/>
        <filter type="and">
            <condition attribute="salesorderid" operator="eq" value="5AC5CBAC-25A0-E211-92B3-00155D815016"/></filter>
        <link-entity name="new_entity" from="new_entityid" to="new_entitylookup">
            <filter type="and">
<condition attribute='new_entityid' operator='eq' value='10ad18f6-c384-e211-b04d-78e3b50834b8'/>
                <attribute name="new_street1"/>
                <attribute name="new_province"/>
                <attribute name="new_postalcode"/>
                <attribute name="new_city"/>
            </filter>
        </link-entity>
    </entity></fetch>

知道怎么做吗?

谢谢和最好的问候..

【问题讨论】:

  • 那么你的问题是如何连接 xml 是 Javascript 吗?还是您的 Fetch xml 不起作用?

标签: javascript dynamics-crm-2011 dynamics-crm crm


【解决方案1】:

如果问题是为什么您的 fetch 不起作用,那可能是因为您的属性嵌套在节点中。试试这样:

<fetch mapping="logical">
<entity name="salesorder">
    <attribute name="salesorderid"/>
    <attribute name="new_type"/>
    <attribute name="new_solomonswonumber"/>
    <attribute name="new_resolutioncode"/>
    <attribute name="new_rentalsaleindicator"/>
    <attribute name="new_preferredphone"/>
    <attribute name="name"/>
    <attribute name="new_equipment"/>
    <attribute name="customerid"/>
    <order attribute="new_type" descending="false"/>
    <filter type="and">
        <condition attribute="salesorderid" operator="eq" value="5AC5CBAC-25A0-E211-92B3-00155D815016"/></filter>
    <link-entity name="new_entity" from="new_entityid" to="new_entitylookup">
        <filter type="and">
            <condition attribute='new_entityid' operator='eq' value='10ad18f6-c384-e211-b04d-78e3b50834b8'/>
        </filter> 
        <attribute name="new_street1"/>
        <attribute name="new_province"/>
        <attribute name="new_postalcode"/>
        <attribute name="new_city"/>
    </link-entity>
</entity></fetch>

如果问题是如何插入 JS。您可以使用这样的正则表达式 (jsFiddle):

var regex = new RegExp(/<link-entity.*name=[\"\']new_entity[\"\'].*>.*<filter[^>]*>/);

fetch = fetch.replace(regex, '$&' + newCondition)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-24
    • 2011-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多