0

I have the following fetch XML query:

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

I have a business need where I need to insert the following condition using java script:

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

So that the final fetchxml is as follow:

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

Any idea how to do this ?

Thanks and best regards..

1
  • 1
    So is your question how to concatenate xml is Javascript? Or is your Fetch xml not working? Commented May 24, 2013 at 12:46

1 Answer 1

2

If the question is why your fetch isn't working, it might be because you have your attributes nested in your node. Try it like this:

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

If the question is how do you insert you JS. You can use a regex like this (jsFiddle):

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

fetch = fetch.replace(regex, '$&' + newCondition)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.