Skip to main content

Notifications

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.

  • Juliyahobs Profile Picture
    5 on at
    RE: How to Retrieve account Id / name which is connected to view?

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

  • Loran Gray Profile Picture
    15 on at
    RE: How to Retrieve account Id / name which is connected to view?

    Hi, Thanks For Helping People...

  • HarryZang Profile Picture
    240 on at
    RE: How to Retrieve account Id / name which is connected to view?

    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 )

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,309 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,162 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans