Announcements
Hi
I'm facing the following problem: The plugin needs to excecute a FetchXML with conditions and filters when a specific view is triggered. The view can be accessed via a parent Acc to show related hardware to the Acc.
In addition, the FetchXML is static scripted and not dynamic (Script is shown below). However I want to manipulate the FetchXML by setting the 'primaryaccountid' and 'ParentAccountName' with variables which I retrieved from the IOrganizationService to make it dynamic. Is that possible?
My Plugin is registered on RetriveMultiple message and triggers on the correct view (checked via Guid of view and name as well).
The FetchXML script should be correct because it was created with 'Advanced find' from CRM.
System.String fetchXml =
@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='mainframe'>
<attribute name='name' />
<attribute name='createdon' />
<attribute name='systemnumber' />
<attribute name='mainframetypeid' />
<attribute name='cpus' />
<attribute name='usage' />
<attribute name='decommisiondate' />
<attribute name='primaryaccountid' />
<attribute name='node_name' />
<attribute name='cores_per_cpu' />
<attribute name='mainframeid' />
<attribute name='parent_account' />
<order attribute='name' descending='false' />
<filter type='and'>
<filter type='or'>
<condition attribute='primaryaccountid' operator='eq' uiname='ParentAccountName' uitype='account' value='{EC1234A-DF6E-DF11-8121-005056A707B1}' />
<condition attribute='parent_account' operator='eq' uiname='ParentAccountName' uitype='account' value='{EC1234A-DF6E-DF11-8121-005056A707B1}' />
</filter>
</filter>
<link-entity name='mainframetype' from='mainframetypeid' to='mainframetypeid' visible='false' link-type='outer' alias='a_bd24b62d306adf118121005056a707b1'>
<attribute name='max_cores_per_cpu' />
<attribute name='createdonbehalfby' />
</link-entity>
</entity>
</fetch>";
Thats how I trigger on the view:
if (context.InputParameters.Contains("Query") & context.InputParameters["Query"] is QueryExpression & context.MessageName == "RetrieveMultiple")
{
Guid viewId = new Guid("127dee92-0e90-4e6c-90bb-b281498d890b");
String viewName = "Hardware Associated View";
var savedQueryFetchXml = (from q in orgContext.CreateQuery("savedquery") //orgContext.CreateQuery("savedquery")
where (Guid)q["savedqueryid"] == viewId
&& (string)q["name"] == viewName
&& (string)q["fetchxml"] != null
select q["fetchxml"]).FirstOrDefault();
Thanks in advance.
Hi, you can always use the organization service and another fetchxml to retrieve the parentaccount id and parent account name.
for example:
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
var AccountId = context.PrimaryEntityId;
var AccountDetails = service.Retrieve("account", AccountId, new ColumnSet("parentaccountid"));
//now you can get the parentaccount id from AccountDetails
replace the hardcoded guid in your fetxhxml with the parentaccountid you get.
(once you got the parentaccountid, it should be enough as the unique identifier as filter, so you do not need the parentaccountname anymore )
André Arnaud de Cal...
293,309
Super User 2025 Season 1
Martin Dráb
232,162
Most Valuable Professional
nmaenpaa
101,156
Moderator