Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Dynamics Plugin - get account GUID

(0) ShareShare
ReportReport
Posted on by 5

Hello, I’m hoping someone might be able to help me, I’m new to creating plugins so apologies if this has been asked before.

 

I am trying to import some external data into Dynamics using a virtual entity. I have successfully created a plugin for this with the Retrieve and RetrieveMultiple event handlers and this shows me all the data in a subgrid using a sample API. However, the API I’m using requires me to filter the results as part of the request by passing a parameter, in this case it’s a company ID. This company ID is saved as a field in the account entity but I’m struggling to get this at run time in the plugin that is making the API call.

 

On the account form I have a tab that will be for Licence Codes that are saved in an external source, I can use an API call to retrieve these, but I need to know the company ID before I can make the call. Is there a way I can get the GUID of the account that I’m using (i.e. the account on the open form) as I can then get the company ID using a simple queryExpression? Using Guid Id = context.PrimaryEntityId only returns 00000000-0000-0000-0000-000000000000 not the GUID of the account record.

Any help would be greatly appreciated

  • RE: Dynamics Plugin - get account GUID

    Hi Dave,

    dynamicsninja.blog/.../

    Please refer above link on virtual entity data provider.

    If you are going to add virtual entity as subgrid in account. You can combine both and try.

    Sorry for the inconveniences caused. I didn't know that you were talking about virtual entity data provider at first.

    Regards,

    Prakash

  • Dave P Profile Picture
    Dave P 5 on at
    RE: Dynamics Plugin - get account GUID

    Hi Prakash

    Thanks for your help, but I'm not sure what I can send you as I'm just trialling the managed solution from the link you shared. I have simply downloaded it and imported the solution,  enabled SDK Message Processing Steps and then opened the Contact JR form and I can see a phone call on the timeline but nothing appears in the "ALL ACTIVITIES" subgrid, and when I check the Tracer it says "Not expected context". I'm not sure what else I can share with you, I thought the solution would have everything in it that you need to see the code actually work. I have not started work on the code for Licence Code, im using this example to see how it all works jlattimer.blogspot.com/.../creating-custom-virtual-entity-data.html Is it possible to merge both these into a single example to see how it works?

  • Suggested answer
    RE: Dynamics Plugin - get account GUID

    Hi Dave,

    Try the below steps.

    Please create lookup field in virtual entity that points to account. Do not add inside any form. That will automatically create relationship between account and the virtual entity.

    Open the existing subgrid configuration for virtual entity in account, select Records as "only related records" instead of "all records". I think in your case at present it will be for all records.

    Then follow the link which I shared above.

    Instead of regardingobjectid now it will be schema name of the lookup field which you have created.

    I am not sure how I am going to help without code.

    I hope this might help you.

    Regards,

    Prakash

  • Dave P Profile Picture
    Dave P 5 on at
    RE: Dynamics Plugin - get account GUID

    Hi Prakash

    I'm simply using the managed solution from the link you sent me, I'm trying to prove that I understand the code and how it works before trying to build the final solution with the correct API.

  • RE: Dynamics Plugin - get account GUID

    Hi Dave,

    Can you please show me the subgrid configuration and plugin code.

    I might take a look into it.

  • Dave P Profile Picture
    Dave P 5 on at
    RE: Dynamics Plugin - get account GUID

    Hi Prakash,

    The virtual entity will be added as a subgrid on a main Account form under its own tab so the data will only need to be loaded if the user opens that tab. At present I have not added any relationship between account and the virtual entity, this will be what the CompanyID will be for, so when you open the tab, it will get the CompanyID and inject that to the API call in the RetrieveMultiple Class to only return the licences that are associated with that company. Any ideas what might be causing the sample code to return those errors?

  • RE: Dynamics Plugin - get account GUID

    Hi Dave,

    Yes, you can use the existing retrieve multiple plugin.

    From regardingobjectid you will be able to get account id from value property.

    I have few questions,

    1. Is virtual entity added as subgrid in account ? Any relationship has been created between virtual entity and account?

    2. How will you filter virtual entity based on account. Is there any field available, to which it match account and virtual entity?

    I am sure there will be no lookup has been created in that virtual entity.

    Regards,

    Prakash

  • Dave P Profile Picture
    Dave P 5 on at
    RE: Dynamics Plugin - get account GUID

    Hi Prakash, Thanks for the reply. I think I understand what this is trying to do, not 100% how I would implement implement this with a virtual entity. Would I use my existing plugin registered as the Data Provider and use the existing RetrieveMultiple class and simply add ReplaceRegardingCondition to it to gain access to GUID of the related record, in this case Account? I presume I would need to add a similar set of conditions to the view used on the subgrid? I have imported the unmanaged solution into my sandbox environment and tried to run it and when I check the trace logs all I get is "Not expected context" and then "Not expected query" any ideas what I'm doing wrong?

  • RE: Dynamics Plugin - get account GUID

    Hi Dave,

    This might help you.

    While configuring subgrid for virtual entity in account select Records as "only related records". In background fetch XML will be added with regardingobjectid with parent account id.

    In retrievemultiple plugin, output collection will get it as fetch XML and from that get regardingobjectid value that is account id. Perform one retrieve for account using above fetched value inside the same plugin to get company id. Add the company ID filter to fetch XML to only get those related records and remove regardingidobject filter from the fetch XML.

    This can be achieved using one single retrieve multiple for virtual entity.

    FYR, refer this link 

    https://jonasr.app/2016/04/all-activities/

    The above link is all about activities but requirement is same.

    Let me know if you need any more details.

    Mark it as answer if this solves your problem.

    Regards,

    Prakash

  • Dave P Profile Picture
    Dave P 5 on at
    RE: Dynamics Plugin - get account GUID

    Hello Guido, thank you for coming back to me so quickly. I’m not sure I explained the situation very well, so I will try again.

    I have written a single Plugin which has 2 classes in it, one for Retrieve and another for RetrieveMultiple, then using the Plugin Registration Tool I have registered the dll file as a new assembly as per the guidance notes. I have then Registered a new Data Provider and selected the assembly from the previous step and set the 2 event handlers as the Retrieve and RetrieveMultiple classes and then created the data source again as per the instructions.

    I have added the new Virtual Entity Data Source into Dynamics, created the Virtual Entity and set the data source to be the one we just added. I have then added the appropriate fields to the Virtual Entity and added the tab to the accounts form along with the subgrid.

    When I then open the account form I can go to the new tab and the API call is made and the data is displayed as expected, perfect!

    However, this is just a test to make sure I understand how this all works, what I now need to do is to use the API for the licence codes rather than some other test API. The different is, in the test API, the retrieveMultiple class returns all the records, so I could then filter them based on a relationship or anything else I wanted to, however in the API for the licence codes, retrieveMultiple requires an ID as a parameter so it only returns the Licence codes for that company. So, what I need to do is to read the CompanyID field (This is just an Integer) from the open form and then pass that to the API call.

    But the problem I’m having is that the RetrieveMultiple class seems to be acting upon the Virtual Entity and not the Account form so when I ask for the GUID it doesn’t return the correct value. I have tried adding different classes for getting the Account Info by adding steps into the plugin so it happens on retrieve of an account and whilst this gives me the GUID I then cant pass to the RetrieveMultiple class to pass onto the API call.

    I’m stuck as to how I move forward with this, I seem to be able to get the info I want/need in different plugins but cant seem to join them all together. Please can you advise how I can access the Account GUID from the RetrieveMultiple plugin which is for the Virtual Entity?

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans