Announcements
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
Hi,
Is there any reason why you have selected Execution value as 2 in your Post operation plugin?
Can you try changing it to 1 and see if it works.
Do you have any other business logic in your plugin or you are only creating Application process record when Application is created?
Can you please share the plugin trace log error?
I hope you are not checking and getting error while debugging, and also you have disabled your profiler.
Please mark my answer verified if this is helpful!
Regards,
Bipin Kumar
Follow my Blog: xrmdynamicscrm.wordpress.com/
Hi Bipin ,
Thanks for the reply
I tried that as well i was just trying all possible Alternatives to use the record ID of target Entity. But in Async it works. i am trying to figure out why it is not working when I run it as synchronous.
i am using another Plugin Pre operation on Create of same record (Error free Plugin the runs well), and this one is for post operation , wondering if that has to do anything with this. Because i had worked on similar use case and it was working fine where i just had one post operation plugin.
Kindly help me with this.
Thanks in Advance,
Harshith
Hi,
Why don't you take Application record Id from Target Entity as below -
APentity.Attributes["ijp_application"] = new EntityReference("ijp_application", appCreate.Id);
Please mark my answer verified if this is helpful!
Regards,
Bipin Kumar
Follow my Blog: xrmdynamicscrm.wordpress.com/
Hi Andrew,
thanks for the quick reply
I tried that one as well , like i am trying every possible way but GUID is not found its little Weird, Plugins are being Intermittent for me.
i am using another Plugin Pre operation on Create of same record (Error free Plugin the runs well), and this one is for post operation , wondering if that has to do anything with this. Because i had worked on similar use case and it was working fine where i just had one post operation plugin.
Please share your thoughts on this !
it works if i make second plugin Asynchronous maybe because there is some delay in executing Async requests.
Thanks in Advance.
Hello,
Try to replace line
APentity.Attributes["ijp_application"] = new EntityReference("ijp_application", context.PrimaryEntityId);
with line
APentity.Attributes["ijp_application"] = appCreate.ToEntityReference();
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156