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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

how to pass dynamic values to fetch xml using javascript

(0) ShareShare
ReportReport
Posted on by

I want to pass dynamic values to my fetch xml attributes like

var fetchXMLRecords1 = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
"<entity name='new_test'>"+
"<attribute name='"+fieldname+"'/>"+  //here i want to pass dynamic values
"<filter type='and'>"+
"<condition attribute='new_policyid' operator='eq' value ='"+Policyid+"' />"+
"</filter>"+
"</entity>"+
"</fetch>";
var fetchRecords1 = XrmServiceToolkit.Soap.Fetch(fetchXMLRecords1);
var fetchlength1= fetchRecords1.length;

am getting the lenght count also

but when i try to retrieve the value like this.. am getting onload undefined error.

var fieldname1=fetchRecords1[i].attributes.["+fieldname+"].value;

Suggest solution for this

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: how to pass dynamic values to fetch xml using javascript

    What is the attribute you are trying to retrieve?

    Try

    var fieldname1=fetchRecords1[i].fieldname;

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: how to pass dynamic values to fetch xml using javascript

    Hi,

    you can use XrmServiceToolkit library to do this easily.

    see the post below

    arunpotti.wordpress.com/.../retrieve-records-using-fetch-xml-java-script-in-crm-201113

    Hope this help!

  • Suggested answer
    ManirajKV Profile Picture
    1,477 on at
    RE: how to pass dynamic values to fetch xml using javascript

    Hi Ganashree,

    try this

    var fieldname1=fetchRecords1[i].attributes[fieldname].value;

  • Community Member Profile Picture
    on at
    RE: how to pass dynamic values to fetch xml using javascript

    fieldname contains schemaname of field.

    example if schema name of one field is new_name den fieldname varible will hold value of that schema name

  • Suggested answer
    ManirajKV Profile Picture
    1,477 on at
    RE: how to pass dynamic values to fetch xml using javascript

    Hi Gana,

    you can pass like this, It will work

    <attribute name='new_name' value='"+fieldname+"'/>

  • Community Member Profile Picture
    on at
    RE: how to pass dynamic values to fetch xml using javascript

    while fetching its value it is showing undefined

    var fieldname1=fetchRecords1[i].attributes.["+fieldname+"].value;

    also used var fieldname1=fetchRecords1[i].attributes.[fieldname].value;

  • Suggested answer
    ManirajKV Profile Picture
    1,477 on at
    RE: how to pass dynamic values to fetch xml using javascript

    Hi Gana,

    You have mentioned that fieldname holds the value of the field(new_name). So you should give like this var fieldname1=fetchRecords1[i].attributes.["new_name"].value;

    Otherwise, if u want to pass the attribute / schemaname dynamic, store the schema name in another variable.

    var attName = "new_name";

    fieldname1=fetchRecords1[i].attributes.[attrName].value;

  • Community Member Profile Picture
    on at
    RE: how to pass dynamic values to fetch xml using javascript

    no, it s gvg undefined.

    am using xrmtoolkit.

  • Suggested answer
    ManirajKV Profile Picture
    1,477 on at
    RE: how to pass dynamic values to fetch xml using javascript

    Sorry!! In XRMtoolkit we should pass the variable as extension only.

    It will work like this only. fieldname1=fetchRecords1[i].attributes.new_name.value;

    so no way to pass dynamically. I will try XRMtoolkit and let you know.

  • suresh maurya Profile Picture
    630 on at
    RE: how to pass dynamic values to fetch xml using javascript

    For testing of FetchXML, you can test here online http://msxrmtools.com

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans