Error: 0x80040203 Invalid Argument
I'm new to Dynamics. In preparation for getting lookup values from external data source into Dynamics via a plugin, I wanted to test first with hard coded values with this code. But after I registered the assembly, data provider and data source, I created a virtual entity in dynamics which I linked up to a field (lookup type) on a form. After publishing, clicking on the field throws error - Invalid Argument
using System;
using Microsoft.Xrm.Sdk;
namespace Hardcoded.Names.Plugin
{
public class NamesLookupPlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
serviceFactory.CreateOrganizationService(context.UserId);
var tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
try
{
var results = new EntityCollection();
var itemOne = new Entity
{
["ID"] = Guid.NewGuid(),
["Name"] = "First Item"
};
var itemTwo = new Entity()
{
["ID"] = Guid.NewGuid(),
["Name"] = "Second Item"
};
results.Entities.Add(itemOne);
results.Entities.Add(itemTwo);
context.OutputParameters["BusinessEntityCollection"] = results;
}
catch (Exception e)
{
tracingService.Trace($"{e.Message} {e.StackTrace}");
if (e.InnerException != null)
tracingService.Trace($"{e.InnerException.Message} {e.InnerException.StackTrace}");
throw new InvalidPluginExecutionException(e.Message);
}
}
}
}
I expect to see "First Item" and "Second Item" selectable in the lookup field.
You’re hooking on RetrieveMultiple message in your plug-in. There is also Retrieve message (get single record by EntityReference) - you need to hook on that message as well for your entity.
User contributions licensed under CC BY-SA 3.0