HI ,
i Am working with two Tables Application and Application Process , i am Creating Application Process record within the plugin that runs POST operation to Create of Application.
While Mapping Application to Application Process as a Look up , i am getting an error stating Application with GUID does not Exist even when i am running it in Post operation.
Please help me identify the issue
Sharing the Code Below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using System.ServiceModel;
using Microsoft.Xrm.Sdk.Query;
using System.Text.RegularExpressions;
using Microsoft.Crm.Sdk.Messages;
namespace MyPlugins
{
public class ApplicationProcess_Save : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
// Obtain the organization service reference which you will need for
// web service calls.
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parameters.
Entity appCreate = (Entity)context.InputParameters["Target"];
try
{
Entity APentity = new Entity("ijp_applicationprocess");
APentity.Attributes["ijp_application"] = new EntityReference("ijp_application", context.PrimaryEntityId);
APentity.Attributes.Add("ijp_ijp", (EntityReference)appCreate["ijp_ijp"]);
APentity.Attributes.Add("ijp_hrms", hrmsEntity.ToEntityReference());
APentity.Attributes.Add("ijp_name", hrmsEntity["ijp_employeename"]);
APentity.Attributes.Add("ijp_directmanager", hrmsEntity["ijp_directmanager"]);
Guid CreateAP = service.Create(APentity);
// i am getting an error stating GUID of application not found in the above line
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in MyPlug-in.", ex);
}
catch (Exception ex)
{
tracingService.Trace("MyPlugin: {0}", ex.ToString());
throw;
}
}
}
}
Attaching the Snapshot of running the plugin post operation.
Thanks,
Harshith