Skip to main content

Notifications

Announcements

No record found.

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

Virtual Entity loads data but won't work on views or forms. The entity name doesn't exist. Please specify an existing entity name.

(0) ShareShare
ReportReport
Posted on by 5

Hello,

Sorry if this has been asked before, I have been searching but cannot find an answer to the problem I'm having.

I'm working on Dynamics 365 CE on premises and created a new virtual entity with a custom data provider, the new entity has the following code:

using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Serialization.Json;
using System.Text;

namespace CustomDataProvider
{
    /// 
    /// Retrieves some chosen data for all Launches from the SpaceX API
    /// 
    public class RetrieveMultiplePlugin : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            var service = ((IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory))).CreateOrganizationService(new Guid?(context.UserId));
            var tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            EntityCollection ec = new EntityCollection();

            tracingService.Trace("Starting to retrieve SpaceX Launch data");

            try
            {
                // Get data about SpaceX Launches
                var webRequest = WebRequest.Create("http://lisvpsewi/lifeServices/data.json") as HttpWebRequest; // This file has just one line of data

                if (webRequest == null)
                {
                    return;
                }

                webRequest.ContentType = "application/json";

                using (var s = webRequest.GetResponse().GetResponseStream())
                {
                    List launches = null;
                    using (var sr = new StreamReader(s))
                    {
                        var launchesAsJson = sr.ReadToEnd();
                        

                        using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(launchesAsJson)))
                        {
                            DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings()
                            {
                                UseSimpleDictionaryFormat = true
                            };

                            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List), settings);
                            launches = (List)ser.ReadObject(stream);
                        }

                        tracingService.Trace("Total number of Launches: {0}", launches.Count);
                        ec.Entities.AddRange(launches.Select(l => l.ToEntity(tracingService)));
                    }
                }
            }
            catch (Exception e)
            {
                tracingService.Trace("Exception with message: {0}", e.Message);
            }

            // Set output parameter
            context.OutputParameters["BusinessEntityCollection"] = ec;
        }
    }
}

I loaded the assembly, created the data provider, went to administration, created the data provider there too, in my virtual entity I selected the new data provider and went to test it.

When I try to query it I get the following message:

pastedimage1600093499473v1.png

But if I go to the plugin trace log I can see that it retrieved the data correctly and there's no error there:

pastedimage1600093584745v2.png

Searching  I found that this can be caused due to an update made, but not the cause or the way to fix it, this solution and entity are new.

Is there something I'm missing or does anyone have any idea or why does this happen.

  • lpiedra Profile Picture
    lpiedra 5 on at
    RE: Virtual Entity loads data but won't work on views or forms.

    Thank you, your answer gave me an idea, I was naming my entity wrong in the solution I looked at this line:

    ec.Entities.AddRange(launches.Select(l => l.ToEntity(tracingService)));

    In the ToEntity method I had this:

            public Entity ToEntity(ITracingService tracingService)
            {
                Entity entity = new Entity("cc_spacex_rocket_launch"); //THIS IS THE IMPORTANT LINE
    
                // Transform int unique value to Guid
                var id = flight_number;
                var uniqueIdentifier = CDPHelper.IntToGuid(id);
                tracingService.Trace("Flight Number: {0} transformed into Guid: {1}", flight_number, uniqueIdentifier);
    
                // Map data to entity
                entity["cc_spacex_rocket_launchid"] = uniqueIdentifier;
                entity["cc_name"] = mission_name;
                entity["cc_flight_number"] = flight_number;
                entity["cc_rocket"] = rocket.rocket_name;
                entity["cc_launch_year"] = launch_year;
                entity["cc_mission_patch"] = links.mission_patch;
                entity["cc_presskit"] = links.presskit;
                entity["cc_video_link"] = links.video_link;
                entity["cc_wikipedia"] = links.wikipedia;
                entity["cc_details"] = details;
    
                return entity;
            }

    I saw that the entity name was there, I created a new entity using that name and it worked.

    Thanks a lot!

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Virtual Entity loads data but won't work on views or forms.

    Hello,

    Try to replace line

    EntityCollection ec = new EntityCollection();

    with line

    EntityCollection ec = new EntityCollection()

    {

    EntityName = "put logical entity name here"

    };

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! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans