Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Custom Web API call between two different tenants and two tables

(0) ShareShare
ReportReport
Posted on by 873

Hello everyone,

I have a dataverse table in Tenant A - Environment X called AllowedRecords that has simply the below record:
AllowedRecords-_2D00_-Tenant-A.png
In Tenant B - Environment N, I have a custom table.

What I want to achieve is the below:

  • Every time a user in tenant B tries to add a record, an API call should be executed that will check in Tenant A environment X table allowedrecords if he's still allowed to add records to the table.
  • If the API call, as a result, returned the number of rows that are allowed to be created comparing it to the total count of records in table B and he didn't exceeded the number, it will allow him to save the record, if not, it should throw an error message to the user saying that "The number of records for that table has been exceeded".

Screenshot-2022_2D00_02_2D00_10-220438.png

The purpose of the above is to control the number of records that should be created in table B based on a pre-validation from a table on a completely different tenant and environment.

Could you please provide some helpful resources or a sample to achieve the above requirements?

Any help is highly appreciated.

Best regards,
EBMRay

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,959 Super User 2024 Season 1 on at
    RE: Custom Web API call between two different tenants and two tables

    Hi,

    How we can handle this scenario?

    You can throw error when Record is getting deleted as well so that when any system admin user tries to delete managed solution, system will try to delete records from allowedrecords entity and your workflow will be executed which will throw an error to restrict deleting managed solution.

    In addition could you please provide some resources that I should follow that I can start build my logic.

    docs.microsoft.com/.../write-plug-in

    Use fetchxml to count the existing record count from plugin

    docs.microsoft.com/.../use-fetchxml-construct-query

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • EBMRay Profile Picture
    EBMRay 873 on at
    RE: Custom Web API call between two different tenants and two tables

    Hi Bipin Kumar ,

    Very nice idea to throw an error on Create/Update of allowedrecords entity through data import.

    I have a concern for a scenario that might happen for a user that has the sys admin role:

    What about if the system admin user deleted the managed solution that has the allowedrecords entity table? In that case the code that validates if the number of records has been exceeded for the other table will fail and the user will be able to create a record.

    How we can handle this scenario?
    In addition could you please provide some resources that I should follow that I can start build my logic.

    I look forward to your response.
    Thank you!

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,959 Super User 2024 Season 1 on at
    RE: Custom Web API call between two different tenants and two tables

    Hi,

    You can create Ream Time Workflow to throw an error on Create/Update of AllowedRecords Entity -

    CR102.PNG

    Now you deactivate this workflow when you are doing Data Import for the first time and once data is imported, Activate this workflow.

    Now with any security roles, you will not be able to update/create record of AllowedRecords entity from UI/Imports.

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • EBMRay Profile Picture
    EBMRay 873 on at
    RE: Custom Web API call between two different tenants and two tables

    Hi ,

    Thank you for your reply.

    Yes sure, the purpose is I don't want any user that has a system admin role in the other tenant to change the number of records in the allowedrecords table If I create it under the same environment.

    I thought about an approach:

    I could create a managed solution that has this table, imported to the other tenant, and then I can leverage this table in the code directly in the same tenant.

    If the above approach is possible, let's say I need to increase/decrease the number of records I should do the import process of the solution again right and I want to make sure that they can't import anything from excel to inject any record to that table even the users that has the sys admin role?

    What is the best way to do it? Could you please provide the sample code to achieve it?

    I look forward to your response.

    Best regards,

    EBMRay

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Custom Web API call between two different tenants and two tables

    Hi EBMRay,

    Could you explain why you create AllowedRecords table in another Tenant and Environment? If you  create it in the same environment with user create records, it would be easy to go.

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,354 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans