Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Virtual Entity Plugin Target Is Undefined

Posted on by 45

Hi I have an Accounts table with a details form with several subgrids to display different information for the selected company/account. One of the tabs returns licence info and the linked table is a virtual entity, implemented with RetrieveMultiple plugin. This works fine and displays retrieved info as long as I hardwire an account id, but I am unable to get the actual account id of the current company being viewed on the form. I have already browsed around and most posts indicate use of context.InputParameters["Target"] to get the (account) entity current id, but in my code this is not defined. I have tried creating a 1:N relation between account and licences. My code is all standard stuff so nothing to post., but I think I am missing a step somewhere in dynamics setup

.5383.Licences.png

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Virtual Entity Plugin Target Is Undefined

    If you got the answer take a minute and close the thread marking replies that answered your questions as verified by clicking "Yes" at the top of the reply under the question "Did this answer your question"?

  • Suggested answer
    Coolie Profile Picture
    Coolie 45 on at
    RE: Virtual Entity Plugin Target Is Undefined

    Thanks Alex that pointed me in the right direction and I can get the account id now.

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Virtual Entity Plugin Target Is Undefined

    Hello,

      as Andrew has pointed out, you'll need to do some query parsing in the plugin. "Target" input parameter would work IF this plugin were for the account entity (on "Update", for example). Since it's a plugin for the "licence" entity, and it's a Retrievemultiple pluing, you'll need to parse the query and extract account id from the query conditions. I am not sure what the schema name of the account lookup attribute is on that entity, but here is more or less how that code might look like:

    foreach (ConditionExpression condition in conditions)
    {
      if (condition.AttributeName == "<account_id_lookup_attribue_name>")
      {   
         var accountId = condition.Values[0];
      }

    In this loop, you'll likely need to use Criteria.Filters[0].Conditions from the incoming QueryExpression. Might be Criteria.Conditions, though. Or, depending on the complexity of the view, might be something else - you'll likely need to look at the query a little closer then (I'd suggest converting to Fetch from the plugin - see below - and, then, logging it through the tracing service or just by throwing an exception with that fetch in the error message)

    That code would be for the QueryExpression - if it's a virtual entity, you should probably be fine (stage 30? Should be QueryExpression there). Otherwise, if you need to do it in stage 20/40, you may need to "cast" between FetchExpression and QueryExpression (or you may need a similar code to parse FetchExpression): 

    https://docs.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.fetchxmltoqueryexpressionrequest?view=dynamics-general-ce-9

    docs.microsoft.com/.../microsoft.crm.sdk.messages.queryexpressiontofetchxmlrequest

  • Coolie Profile Picture
    Coolie 45 on at
    RE: Virtual Entity Plugin Target Is Undefined

    Ah ok. Thanks for your help Andrew.

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Virtual Entity Plugin Target Is Undefined

    The code I provided is not a copy-past-done thing. In order to resolve your task, you should check how the author of the code works with the query and use a similar approach in your code.

    And just FYI there are 3 types of Power Apps at the moment - Model-Driven Apps (that you use as far as I understood from your screenshot), Canvas Apps, Portal Apps.

    Good luck.

  • Coolie Profile Picture
    Coolie 45 on at
    RE: Virtual Entity Plugin Target Is Undefined

    Thanks Andrew. I tried that - it comes back with recordId (guid) of 0000... I notice it references Canvas App but I'm using Power Apps. I don't understand the code you suggested because there is no reference in it to the parent (account) table.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Virtual Entity Plugin Target Is Undefined

    You can check the following repo as an example - github.com/.../TestEntityPlugin.cs

  • Coolie Profile Picture
    Coolie 45 on at
    RE: Virtual Entity Plugin Target Is Undefined

    Hi Andrew thanks for quick response. That is my problem - how do I get the current account record id in RetrieveMultiple?

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Virtual Entity Plugin Target Is Undefined

    Hello,

    You won't get the reference to the parent account from Target. Generally speaking, what you implement is the plugin that handles retrievemultiple message and the id of the account is inside that query.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans