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)

Add a dynamic variable value for a attribute in fetchxml

(0) ShareShare
ReportReport
Posted on by

Hi Guys,

Everytime and everywhere i see in fetchxml people use only harcoded values i got a scenerio were i need to pass a  dynamically  a string variable please suggest note this c# code

string dynamic ="xyz";

string fetch3 = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='hd_cuscatmust'>
<attribute name='hd_cuscatmustid' />
<attribute name='hd_cusseqnum' />
<attribute name='createdon' />
<order attribute='hd_cusseqnum' descending='false' />
<filter type='and'>
<condition attribute='hd_cusmercod' operator='not-null' />
<condition attribute='hd_cuscatcod' operator='not-null' />
<condition attribute='hd_cusmercod' operator='eq' value=""+dynamic+@"">
</filter>
</entity>
</fetch>";

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    its throws a invalid xml exception

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Try to use following:

    string dynamic ="xyz";

    string fetch3 = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>

    <entity name='hd_cuscatmust'>

    <attribute name='hd_cuscatmustid' />

    <attribute name='hd_cusseqnum' />

    <attribute name='createdon' />

    <order attribute='hd_cusseqnum' descending='false' />

    <filter type='and'>

    <condition attribute='hd_cusmercod' operator='not-null' />

    <condition attribute='hd_cuscatcod' operator='not-null' />

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

    </filter>

    </entity>

    </fetch>";

  • Community Member Profile Picture
    on at

    Works awesome thank you Andrii

  • Community Member Profile Picture
    on at

    please close the thread by verifying the answer it might be helpful to others  

  • Community Member Profile Picture
    on at

    not mine sorry its signature

  • Suggested answer
    Aman Kothari Profile Picture
    on at

    Hi,

    You can also use String.Format method for providing dynamic value to string.

    Here is example

    string dynamic ="xyz";

    string fetch3 =String.Format(@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
    <entity name='hd_cuscatmust'>
    <attribute name='hd_cuscatmustid' />
    <attribute name='hd_cusseqnum' />
    <attribute name='createdon' />
    <order attribute='hd_cusseqnum' descending='false' />
    <filter type='and'>
    <condition attribute='hd_cusmercod' operator='not-null' />
    <condition attribute='hd_cuscatcod' operator='not-null' />
    <condition attribute='hd_cusmercod' operator='eq' value='{0}'>
    </filter>
    </entity>
    </fetch>", dynamic);

    For more info about String.Format methoe please check below url

    https://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx

    Thanks

  • Albert_ Profile Picture
    458 on at

    Hi sir,

    I use SQL Server BI Develope, and I put a textbox from toolbox in top of the report.

    How can I do it dynamically?

    I mean fill the value of a field with that end-user filled out string in the textbox.

  • Community Member Profile Picture
    on at

    Hi Andrew.. I have a question. I have a CRM application and i am pulling data from CRM using Kingsway soft CRM source editor.

    In that i am writing the fetchXML, but i would to like to one of the column value into a variable.

    I tried below and its not working, please help.

    <fetch version="1.0" mapping="logical" aggregate="true">

    <entity name=@[User::tablename]>

      <attribute name=@[User::ColumnName] alias=@[User::tableAlias] aggregate="countcolumn" />

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

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