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.
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. :)
showing same error.
if your fetchxml is stored inside a string you should do something like
...<condition attribute='tpamm_plantype' operator='eq' value='" + PlanType.Id +"' />...
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).}
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
Please check my question again, I added some more information regarding my plugin.
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.
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
hi sir
thax for reply
my table has a lookup field. if I delete this condition how this plugin work with lookup field.
you need to remove the whole filter if you want to retrieve the records but you are limited to 5000 records
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,522 Super User 2024 Season 2
Martin Dráb 228,441 Most Valuable Professional
nmaenpaa 101,148