0

I know this question is very basic, but I have been researching for a week and I have not found the solution. In my work I have been asked to find a way to connect to the data and solutions of PowerApps (Dataverse) from PowerShell or Visual Studio.

I've been doing my research and I am able to connect and get data, but I still haven't been able to create a custom entity (table). I have followed this tutorial Create entities using the Organization Service and this is the code I have:

static void Main(string[] args)
    {
        string url = "xxxxxxxx"; 
        string userName = "xxxxxxxx";
        string password = "xxxxxxxx";

        string conn = $@"
        AuthType = OAuth;
        UserName = {userName};
        Password = {password};
        Url = {url};
        AppId = 51f81489-12ee-4a9e-aaae-a2591f45987d;
        RedirectUri = app://58145B91-0C36-4500-8554-080854F2AC97;
        LoginPrompt = Auto;
        RequireNewInstance = True";

        var svc = new CrmServiceClient(conn);

        using (svc)
        {
            Entity entitytest = new Entity("test");
            
            var vid = svc.Create(entitytest);
            Guid accountid = vid;
        }
    }

It connects correctly (I censored the personal data), but when executing it I get this error in this line "var vid = svc.Create(entitytest);":

System.ServiceModel.FaultException: The entity with a name = 'entitytest' with namemapping = 'Logical' was not found in the MetadataCache. MetadataCacheDetails: ProviderType=Dynamic, StandardCache=True, IsLoadedInStagedContext = False, Timestamp=1084883, MinActiveRowVersion=1084883, MetadataInstanceId=34390963, LastUpdated=2021-05-30 11:49:56.803

What am I doing wrong? Do you know sites with complete examples?

Luis Gouveia
  • 8,334
  • 9
  • 46
  • 68
Anthorio
  • 13
  • 3
  • Not sure how this handled via PowerApps, but could it be that you did not publish your newly created custom entity `chorizo`? (I only ever created custom entities from Dynamics 365 CE) – Filburt May 31 '21 at 08:35
  • Any relevance? https://powerusers.microsoft.com/t5/Connecting-To-Data/Dynamics-365-connector-and-CDS-connector-failing-to-connect-to/td-p/340210 – Anton Krug May 31 '21 at 09:14
  • @Filburt Publishing it returns me false instead of true. I'm going to look for information on that. Thank you :) – Anthorio May 31 '21 at 09:42
  • @Anthorio The tutorial you linked refers to creating records of an existing entity/table - did you create your entity/table `test` like described in [Create a custom table that has components in Power Apps](https://learn.microsoft.com/en-us/powerapps/maker/data-platform/create-custom-entity)? Documenation can be a little misleading in using *entity* as a table as well as a record in a table. – Filburt May 31 '21 at 11:30
  • @Anthorio Can you please show the properties of that entity/table in PowerApps? It seems odd that your error refers to a different logical name than the one you are using in your code. – Filburt May 31 '21 at 11:33
  • 1
    @Filburt Thanks for the help, I want to create a table in PowerApps, not a record, so it doesn't exist before. Sorry for the confusion. – Anthorio Jun 01 '21 at 06:22
  • 1
    @Anthorio If you intend to create a custom entity via code, you need to look into [Create custom entity](https://learn.microsoft.com/en-us/powerapps/developer/data-platform/org-service/create-custom-entity) and related MetadataRequests. – Filburt Jun 01 '21 at 09:26
  • @Filburt Thanks, that is the problem. I am now researching how to handle the issue of metadata. – Anthorio Jun 02 '21 at 06:55

0 Answers0