Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

fechXML queue stored on database and used in plugin

Posted on by 30

i'm trying to create a rules table that would store predefined fetchXML queries to be used in in a C# plugin,   i know that i can use the follwing code in a plugin

var value = "something";

var fetchXml = "<fetch>";
fetchXml += $"<entity name='account'>";
fetchXml += " <all-attributes />";
fetchXml += " <filter>";
fetchXml += $" <condition attribute='xxx_field' operator='eq' value='{value}'/>";
fetchXml += " </filter>";
fetchXml += "</entity>";
fetchXml += "</fetch>";

var entitySyncRules = service.RetrieveMultiple(new FetchExpression(fetchXml));

and it works no problem the code replaces the {vale} with something . now Ii'm trying to take this to an other level.  i have a rule table entity that would store the fetchXML this would enable me to build and edit the fetchXML dinamicly 

[rule entity]

storeFetchXML = <fetch><entity name='account'><all-attributes /><filter><condition attribute='xxx_field' operator='eq' value='{value}'/></filter></entity></fetch>

in the plugig

value = "something"

fetchXML = ruleentity.GetAttributeValue<string>("storeFetchXML")

var entitySyncRules = service.RetrieveMultiple(new FetchExpression(fetchXml));

this code do not work,  it doest replace the {value} with the content on the variable.  it leave the string as is .

is there a way to make sure that the code does the code replace .  if tried the following

fetchXML = $ruleentity.GetAttributeValue<string>("storeFetchXML")

fetchXML = $"{ruleentity.GetAttributeValue<string>("storeFetchXML")}"

if i'm going down the wrong path... this is possible.  but is there a way to use a stored parametrized fetchXML in a queue with the paramater being replace at run time. (yes i know the field must exist in the code)

  • Suggested answer
    Fubar Profile Picture
    Fubar 2,750 on at
    RE: fechXML queue stored on database and used in plugin

    Use string interpolation or string.Format and substitute in your values in an array.

    e.g.

    string.Format(query, paramvaluesArray);

    Where query = normal fetch with substitution such as

    <condition attribute='name' operator='eq' value='{0}' />

    <condition attribute='websiteurl' operator='eq' value='{1}' />

    The values in the Array are then substituted in sequence into to {0} etc

    In our case we read from another entity the query, and a comma separated list of values.  We convert the comma separated list to an Array and this allows us to vary the query conditions and the number of substituted values without code changes.

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