web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Suggested answer
    PranavShroti Profile Picture
    4,510 on at

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

  • Suggested answer
    Sreevalli Profile Picture
    3,256 on at

    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?

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    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
    Pawar Pravin  Profile Picture
    5,237 on at

    Hi Abdelrhman,

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

  • Abdelrhman Hiba Profile Picture
    321 on at

    i use that fetxhxml to create API for Mobile Application

  • Abdelrhman Hiba Profile Picture
    321 on at

    But anywhere  put GuidArray array ?

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    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
    321 on at

    thanks Goutam

    for your answer

  • Gyllentid Profile Picture
    10 on at

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans