Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

How to pass dynamic variable value as array for a attribute in fetchxml?

Posted on by 321

i want to pass multiple variable to my below FetchXML  for (msdyn_workorderid) parametar 

in my case i pass 10 ststic parametars 

Is there another solution that makes it automatic?

Without installing the number of fild?

My FetchXML:

<fetch distinct="true" >
<entity name="msdyn_workorder" >
<attribute name="msdyn_workorderid" />
<attribute name="msdyn_serviceaccount" />
<attribute name="msdyn_systemstatus" />
<filter type="and" >
<condition attribute="msdyn_workorderid" operator="in" >
<value>24ab086a-2c61-e911-a968-000d3a4648ef</value>
<value>f2871258-2c61-e911-a968-000d3a4648ef</value>
<value>7277083a-2c61-e911-a968-000d3a4648ef</value>
<value>ff2ba362-2a61-e911-a968-000d3a4648ef</value>
<value>6e88794d-2261-e911-a968-000d3a4648ef</value>
<value>0e8fe571-2360-e911-a964-000d3a4647a5</value>
<value>ed51492e-2260-e911-a964-000d3a4647a5</value>
<value>7542cb07-2160-e911-a964-000d3a4647a5</value>
<value>6f42cb07-2160-e911-a964-000d3a4647a5</value>
<value>59bf33e0-9c5f-e911-a964-000d3a4647a5</value>
</condition>
<condition attribute="msdyn_systemstatus" operator="in" >
<value>1</value>
<value>2</value>
<value>3</value>
</condition>
</filter>
</entity>
</fetch>

*This post is locked for comments

  • sroo Profile Picture
    sroo 10 on at
    RE: How to pass dynamic variable value as array for a attribute in fetchxml?

    This is quite difficult to understand where to put it. Am I assuming correctly this is done in Power Auttomate?

  • Abdelrhman Hiba Profile Picture
    Abdelrhman Hiba 321 on at
    RE: How to pass dynamic variable value as array for a attribute in fetchxml?

    thanks Goutam

    for your answer

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: How to pass dynamic variable value as array for a attribute in fetchxml?

    Yes you can declare before preparing the fetchXML like below -

    var GuidArray= ["{25A17064-1AE7-E611-80F4-E0071B661F01}", "{25A17064-1AE7-E611-80F4-E0071B661F01}", "{25A17064-1AE7-E611-80F4-E0071B661F01}"];

  • Abdelrhman Hiba Profile Picture
    Abdelrhman Hiba 321 on at
    RE: How to pass dynamic variable value as array for a attribute in fetchxml?

    But anywhere  put GuidArray array ?

  • Abdelrhman Hiba Profile Picture
    Abdelrhman Hiba 321 on at
    RE: How to pass dynamic variable value as array for a attribute in fetchxml?

    i use that fetxhxml to create API for Mobile Application

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: How to pass dynamic variable value as array for a attribute in fetchxml?

    Hi Abdelrhman,

    Using for loop you can add 'Value' node dynamically as suggested by Pranav

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: How to pass dynamic variable value as array for a attribute in fetchxml?

    Hi ,

    Make sure you are passing GUID within {}.

    You can prepare the fetchXML using Advanced Find. Here is sample  one - 

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="account">
        <attribute name="name" />
        <attribute name="primarycontactid" />
        <attribute name="telephone1" />
        <attribute name="accountid" />
        <order attribute="name" descending="false" />
        <filter type="and">
          <condition attribute="primarycontactid" operator="in">
            <value>{25A17064-1AE7-E611-80F4-E0071B661F01}</value>
            <value>{49A0E5B9-88DF-E311-B8E5-6C3BE5A8B200}</value>
            <value>{9DA07064-1AE7-E611-80F4-E0071B661F01}</value>
          </condition>
        </filter>
      </entity>
    </fetch>

    Try to write like below  - 

    var fetchXml = "<fetch distinct='true'>"+
        "<entity name='msdyn_workorder'>" +
        "<attribute name='msdyn_workorderid'/>" +
        "<attribute name='msdyn_serviceaccount'/>" +
        "<attribute name='msdyn_systemstatus'/>" +
        "<filter type='and'>" +
        "<condition attribute='msdyn_workorderid' operator='in'>"
    
    for (var i = 0; i < GuidArray.length; i++) {   // Assuming that you have array of Guid which is GuidArray .
            fetchXml += "<value>" + GuidArray[i] + "</value>";
         }
    
        fetchXml += "</condition ><condition attribute='msdyn_systemstatus' operator='in' >" +
            "<value>1</value>" +
            "<value>2</value>" +
            "<value>3</value>" +
            "</condition>" +
            "</filter >" +
            "</entity >" +
            "</fetch >";


  • Suggested answer
    Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: How to pass dynamic variable value as array for a attribute in fetchxml?

    Hi,

    Could you please help me understanding more about the situation, where are you using this fetchxml? and from where you are fetching these static guid id's?

  • Suggested answer
    PranavShroti Profile Picture
    PranavShroti 4,510 on at
    RE: How to pass dynamic variable value as array for a attribute in fetchxml?

    Hi

    Unfortunately, there is no direct way of doing this in current SDK version.  

    You can try giving individual elements as arguments: (indicative code)

    string fetchxml = @"<fetch mapping='logical'>

    <entity name='contact'>

    <attribute name='firstname' />

    <filter type='and'>

    <condition attribute='lastname' operator='not-in'>

    <value>"+array[0]+@"</value>

    <value>"+array[1]+@"</value>

    </condition>

    </filter>

    </entity>

    </fetch>";

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans