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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Fetch Query Expression

(0) ShareShare
ReportReport
Posted on by 160

Hi

I am using this query in my plugin to fetch the data of a child table. But in this xml code the condition is set to a specific record(A). I want to use this code for all records associated with PlanType table record via Lookup. how i can do this.

<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='tpamm_plantyperequirement'>
<attribute name='tpamm_name' />
<attribute name='tpamm_limitbyage' />
<attribute name='tpamm_agecriteria' />
<attribute name='tpamm_age1' />
<attribute name='tpamm_age2' />
<attribute name='tpamm_limitmaxperson' />
<attribute name='tpamm_maxperson' />
<attribute name='tpamm_plantyperequirementid' />
<order attribute='tpamm_name' descending='false' />
<filter type='and'>
<condition attribute='tpamm_plantype' operator='eq' uiname='A' uitype='tpamm_plantype' value='{645ACDBA-8BC7-EC11-A7B5-002248D5CE0C}' />
</filter>
</entity>
</fetch>"

I am writing a plugin on Table A which has lookup field from "Plan Type" Table. "Requirement" Table also have a lookup field from table "plan Type". I used above mentioned Fetch query to get data from Requirement table. Please refer this info of my project to answer my question.

pastedimage1651642001239v1.png

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    you need to remove the whole filter if you want to retrieve the records but you are limited to 5000 records

  • happysingh0009 Profile Picture
    160 on at

    hi sir

    thax for reply

    my table has a lookup field. if I delete this condition how this plugin work with lookup field.

  • Guido Preite Profile Picture
    54,086 Moderator on at

    you just put a fetchxml query, you didn't post your plugin code or what this plugin is achieving.

    right now that fetchxml return "tpamm_plantyperequirement" records when the "tpamm_plantype" lookup is equals to that guid, if you remove the whole filter the query will return all the "tpamm_plantyperequirement" records (up to 5000), what you do with the returned result (few records or all records) depends on your logic, not on this fetchxml query

  • happysingh0009 Profile Picture
    160 on at

    if i remove condition then how my plugin (On parent table) will found the associated record in child table. As that condition is presenting a lookup relationship between 2 table , i am getting record associated with record in parent table.

    i tried without condition, in this case the plugin is providing any random record but i need a record associated with the parent record.

  • happysingh0009 Profile Picture
    160 on at

    Please check my question again, I added some more information regarding my plugin.

  • Verified answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    ok, now your requirement is more clear.

    if your plugin runs on the tpamm_plantype entity, inside your plugin you probably will have this kind of code:

    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    Entity currentRecord = null;
    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
    {
        currentRecord = (Entity)context.InputParameters["Target"];
        if (currentRecord.LogicalName != "tpamm_plantype") { return; }
    }

    so inside currentRecord.Id you will have the GUID of the current tpamm_plantype

    after you edit your fetchxml to change the guid defined there with the guid coming from current record and you can fetch the related table (keep in mind that for the fetch you don't need uiname an uitype

    hope it helps

  • happysingh0009 Profile Picture
    160 on at

    PlanType.Id= Guid.NewGuid();

    <condition attribute='tpamm_plantype' operator='eq' value='PlanType.Id' />

    i tried above statements to set GUID in the condition, but it is giving error of {An exception System.FormatException was thrown while trying to convert input value 'PlanTypeRef.Id' to attribute 'tpamm_plantyperequirement.tpamm_plantype'. Expected type of attribute value: System.Guid. Exception raised: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).}

  • Verified answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    if your fetchxml is stored inside a string you should do something like

    ...<condition attribute='tpamm_plantype' operator='eq' value='" + PlanType.Id +"' />...

  • happysingh0009 Profile Picture
    160 on at

    showing same  error.

  • Suggested answer
    happysingh0009 Profile Picture
    160 on at

    Thank you for your reply. I was passing the dynamic value to fetchquery but in the same way as we pass static value. that was the error. Thank u for suggestion to concatenate the Expression. its working now. :)

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Syed Aqib Raza Profile Picture

Syed Aqib Raza 125

#2
ParthPatel249 Profile Picture

ParthPatel249 87

#3
11manish Profile Picture

11manish 85 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans