2013-05-23 2 views
0

У меня есть следующий выборки запроса XML:CRM 2011: Вставить условие запроса fetchXML с помощью JavaScript

<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 Script:

<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> 

Любая идея, как это сделать?

Спасибо и наилучшие пожелания ..

+1

Так это ваш вопрос, как сцепить XML является Javascript? Или ваш Fetch xml не работает? – Daryl

ответ

2

Если возникает вопрос, почему ваша выборка не работает, это может быть потому, что у вас есть свои атрибуты, вложенные в вашем узле. Попробуйте следующее:

<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) 
Смежные вопросы