Skip to main content
Dynamics 365 general forum
Unanswered

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

editSubscribe (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.

Categories:
  • Juliyahobs Profile Picture
    Juliyahobs 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
    Loran Gray 15 on at
    RE: How to Retrieve account Id / name which is connected to view?

    Hi, Thanks For Helping People...

  • HarryZang Profile Picture
    HarryZang 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 )

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Sundar…

Industry experts answer burning questions directly from our amazing Community…

Enabling Copilot Case and Conversation…

Agents can easily recap an ongoing chat, transcribe a voice conversation…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,030 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,562 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans