I am experimenting with CRM Plugins. My end goal is to create a plugin that will run another program that just adds project credentials to an excel file. For my sample project, I essentially just followed https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/tutorial-write-plug-in. The example provided here was excellent and taught me a lot about Plugins. The issue I am having is, whenever I try to execute code that was not involved in the tutorial, I get an error and the debug process doesn't even hit my break point. When I remove my personal code from the function, it works fine.
public class PostCreateContact : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
//Process firstProc = new Process();
//firstProc.StartInfo.FileName = "notepad++.exe";
//firstProc.StartInfo.WorkingDirectory = "C:\\Program Files (x86)\\Notepad++\\notepad++.exe";
//firstProc.EnableRaisingEvents = true;
//firstProc.Start();
if (context.InputParameters.Contains("Target")&& context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
try
{
Entity followup = new Entity("task");
followup["subject"] = "Send e-mail to the new customer.";
followup["description"] = "Follow up with the customer. Check if there are any new issues that need resolution.";
followup["scheduledstart"] = DateTime.Now;
followup["scheduledend"] = DateTime.Now.AddDays(2);
followup["category"] = context.PrimaryEntityName;
if (context.OutputParameters.Contains("id"))
{
Guid regardingobjectid = new Guid(context.OutputParameters["id"].ToString());
string regardingobjectidType = "contact";
followup["regardingobjectid"] = new EntityReference(regardingobjectidType, regardingobjectid);
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
service.Create(followup);
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
}
}
}
The 5 lines of code that I have commented out are my personal code i mentioned. If I were to un-comment out those lines. The code will not hit my break point. My break point was set below the "public void Execute(IserviceProver servicerProvider)" line. Could someone explain to me why it immediately fails whenever I insert my own code to perform a non CRM related task?
Also, besides attempting to open up notepad++, attempting to throw a message box will not work either.