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 :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

How to Retrieve account Id / name which is connected to view?

(0) ShareShare
ReportReport
Posted on by 25

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.

I have the same question (0)
  • HarryZang Profile Picture
    240 on at

    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 )

  • Loran Gray Profile Picture
    15 on at

    Hi, Thanks For Helping People...

  • Juliyahobs Profile Picture
    5 on at

    Yes They are Doing Amazing Work. Helping Each Other Is the Best thing to make a Best Community!...

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Pallavi Phade Profile Picture

Pallavi Phade 102 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 67

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans