Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Runtime changes by using fetchXMLQuery.

(0) ShareShare
ReportReport
Posted on by

Hii everyone.

I am trying to pass an dynamic value to an fetchXMLQuery.

Code:-

function ShopOnLoad()
{

alert("Function approached");

string dynamic = "Brand Factory";

string shopFetchXML =@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> 
<entity name='new_myshopping'> 
<attribute name='new_myshoppingid'/> " 
<attribute name='new_shoppingname'/>
<attribute name='new_finalamount'/>
<attribute name='createdon'/>
<order attribute='new_shoppingname' descending='false'/>
<filter type='and'>
<condition attribute='new_shoppingname' operator='eq' value='"+dynamic+@"'/>
</filter>
</entity>
</fetch>" ;

alert("XMLFetch Query Executed");

var shopRecords = XrmServiceToolkit.Soap.Fetch(shopFetchXML);

alert("Multiple data fetched");

if(shopRecords.length > 0 && shopRecords[0].attributes.new_finalamount != undefined)

{

alert("If Condition approached");

alert(shopRecords[0].attributes.new_finalamount.value);
alert(shopRecords[0].attributes.new_shoppingname.value);

}

alert("Finished");

}

I am getting an error of ShopOnLoad is not defined at eval.

I have used all related Web Resources.

*This post is locked for comments

  • RE: Runtime changes by using fetchXMLQuery.

    Thanx Ravi for shairing this online compiler for javascript.

    Once again Thanx.

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 Moderator on at
    RE: Runtime changes by using fetchXMLQuery.

    Hi Ajay,

    You have compile time syntax errors in your code. The code above shared by Iswarya should work but in case you wanted to fix these by yourself, you can try the below JavaScript validator which will tell you all the errors.

    esprima.org/.../validate.html

    Hope this helps.

  • Verified answer
    Iswarya Profile Picture
    Iswarya 1,345 on at
    RE: Runtime changes by using fetchXMLQuery.

    Hi,

    i did changes in your code try this,

    function ShopOnLoad()

    {

       alert("Function approached");

       var dynamic = "Brand Factory";

       var shopFetchXML ="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> "+

       "<entity name='new_myshopping'> "+

       "<attribute name='new_myshoppingid'/>"+

       "<attribute name='new_shoppingname'/>"+

       "<attribute name='new_finalamount'/>"+

       "<attribute name='createdon'/>"+

       "<order attribute='new_shoppingname' descending='false'/>"+

       "<filter type='and'>"+

       "<condition attribute='new_shoppingname' operator='eq' value='"+dynamic+"'/>"+

       "</filter>"+

       "</entity>"+

       "</fetch>" ;

       alert("XMLFetch Query Executed");

       var shopRecords = XrmServiceToolkit.Soap.Fetch(shopFetchXML);

       alert("Multiple data fetched");

       if(shopRecords.length > 0 && shopRecords[0].attributes.new_finalamount != undefined)

       {

           alert("If Condition approached");

           alert(shopRecords[0].attributes.new_finalamount.value);

           alert(shopRecords[0].attributes.new_shoppingname.value);

       }

       alert("Finished");

    }

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,436 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans