Answered by:
Issue with plugins

Question
-
Hi,
I have an issue with the plugins.
I am writing this plugin in another server say server1.
My crm is residing in server2 and server3(both are having the same crm but in different servers).
i register the plugin in one of the servers(server2 or 3).
After registering when i try to run it i am nt getting any error.But the plugin is not working,meaning the record is not getting created as required.
i am using the basic plugin sample in sdk
Please show me where i am wrongusing System; using System.Collections.Generic; using System.Text; using Microsoft.Crm.Sdk; using Microsoft.Crm.SdkTypeProxy; namespace Microsoft.Crm.Sdk.Walkthrough { public class AccountCreateHandler : IPlugin { } }
public void Execute(IPluginExecutionContext context)
{
DynamicEntity entity = null;
// Check if the input parameters property bag contains a target
// of the create operation and that target is of type DynamicEntity.
if (context.InputParameters.Properties.Contains("Target") &&
context.InputParameters.Properties["Target"] is DynamicEntity)
{
// Obtain the target business entity from the input parmameters.
entity = (DynamicEntity)context.InputParameters.Properties["Target"];
// Verify that the entity represents an account.
if (entity.Name != EntityName.account.ToString()) { return; }
}
else
{
return;
}
try
{
// Create a task activity to follow up with the account customer in 7 days.
DynamicEntity followup = new DynamicEntity();
followup.Name = EntityName.task.ToString();
followup.Properties = new PropertyCollection();
followup.Properties.Add(new StringProperty("subject", "Send e-mail to the new customer."));
followup.Properties.Add(new StringProperty("description",
"Follow up with the customer. Check if there are any new issues that need resolution."));
followup.Properties.Add(new CrmDateTimeProperty("scheduledstart",
CrmTypes.CreateCrmDateTimeFromUniversal(DateTime.Now.AddDays(7))));
followup.Properties.Add(new CrmDateTimeProperty("scheduledend",
CrmTypes.CreateCrmDateTimeFromUniversal(DateTime.Now.AddDays(7))));
followup.Properties.Add(new StringProperty("category",
context.PrimaryEntityName));
// Refer to the new account in the task activity.
if (context.OutputParameters.Properties.Contains("id"))
{
Lookup lookup = new Lookup();
lookup.Value = new Guid(context.OutputParameters.Properties["id"].ToString());
lookup.type = EntityName.account.ToString();
followup.Properties.Add(
new LookupProperty("regardingobjectid", lookup));
}
TargetCreateDynamic targetCreate = new TargetCreateDynamic();
targetCreate.Entity = followup;
// Create the request object.
CreateRequest create = new CreateRequest();
create.Target = targetCreate;
// Execute the request.
ICrmService service = context.CreateCrmService(true);
CreateResponse created = (CreateResponse)service.Execute(create);
}
catch (System.Web.Services.Protocols.SoapException ex)
{
throw new InvalidPluginExecutionException(
"An error occurred in the AccountCreateHandler plug-in.", ex);
}
Thanks,
Aarch
Thanks, AarchThursday, May 7, 2009 12:37 PM
Answers
-
Hi, Aarch.
Have you strongly named the assembly?
To do it go to the Properties of project, open tab Signing, click Sign the assembly, create strong name key file.
Have you registered the step using PluginRegistrator?
For catching the Exception better use:
catch (System.Web.Services.Protocols.SoapException ex)
{
throw new Execption(ex.Detail.InnerText);
}
Истина открывается подготовленному уму. Мой блог - http://a33ik.blogspot.com- Edited by Andrii ButenkoMVP, Moderator Thursday, May 7, 2009 12:46 PM
- Proposed as answer by JuergenBeckModerator Thursday, May 7, 2009 1:11 PM
- Marked as answer by JuergenBeckModerator Friday, May 29, 2009 11:50 AM
Thursday, May 7, 2009 12:42 PMModerator -
Hi Aarch,
does your code compile? Your Execute method is outside of the class definition.
Additionally you can debug your PlugIn with Visual Studio, but not with the Express edition.
Best regards,
Jürgen
Jürgen Beck
Dipl. Kfm./Wirtschaftsinformatik
MVP, MCSD.NET, MCITP DBA, MCDBA, MCSE
Microsoft Certified Business Management Solutions Professional
Microsoft Certified CRM Developer
Microsoft Certified Trainer
ComBeck IT Services & Business Solutions
Microsoft Gold Certified Partner
Microsoft Small Business Specialist
Developing & Supporting Business Applications from small business to big enterprises covering scores of sectors
http://www.combeck.de
- Proposed as answer by JuergenBeckModerator Thursday, May 7, 2009 1:11 PM
- Marked as answer by JuergenBeckModerator Friday, May 29, 2009 11:49 AM
Thursday, May 7, 2009 1:11 PMModerator -
Hi Aarch,
Try debugging your plugin
http://code.msdn.microsoft.com/MSCRMPluginDebugger
or do debugging by attaching visual studio debugger to the worker process
or log the error message in a text file to have more understanding of the problem as suggested by above experts
catch (System.Web.Services.Protocols.SoapException ex) { TextWriter log = TextWriter.Synchronized(File.AppendText(@"C:\ErrorLog.txt")); log.WriteLine("Error info" + ex.Detail.InnerText); log.WriteLine("Stack trace" + ex.StackTrace); log.Close(); } catch (Exception ex) { TextWriter log = TextWriter.Synchronized(File.AppendText(@"C:\ErrorLog.txt")); log.WriteLine("Error info" + ex.Message); log.WriteLine("Stack trace" + ex.StackTrace); log.Close(); }
Regards,
Nishant Rana
http://nishantrana.wordpress.com- Marked as answer by JuergenBeckModerator Friday, May 29, 2009 11:50 AM
Friday, May 8, 2009 5:59 AM
All replies
-
Hi, Aarch.
Have you strongly named the assembly?
To do it go to the Properties of project, open tab Signing, click Sign the assembly, create strong name key file.
Have you registered the step using PluginRegistrator?
For catching the Exception better use:
catch (System.Web.Services.Protocols.SoapException ex)
{
throw new Execption(ex.Detail.InnerText);
}
Истина открывается подготовленному уму. Мой блог - http://a33ik.blogspot.com- Edited by Andrii ButenkoMVP, Moderator Thursday, May 7, 2009 12:46 PM
- Proposed as answer by JuergenBeckModerator Thursday, May 7, 2009 1:11 PM
- Marked as answer by JuergenBeckModerator Friday, May 29, 2009 11:50 AM
Thursday, May 7, 2009 12:42 PMModerator -
Hi Aarch,
does your code compile? Your Execute method is outside of the class definition.
Additionally you can debug your PlugIn with Visual Studio, but not with the Express edition.
Best regards,
Jürgen
Jürgen Beck
Dipl. Kfm./Wirtschaftsinformatik
MVP, MCSD.NET, MCITP DBA, MCDBA, MCSE
Microsoft Certified Business Management Solutions Professional
Microsoft Certified CRM Developer
Microsoft Certified Trainer
ComBeck IT Services & Business Solutions
Microsoft Gold Certified Partner
Microsoft Small Business Specialist
Developing & Supporting Business Applications from small business to big enterprises covering scores of sectors
http://www.combeck.de
- Proposed as answer by JuergenBeckModerator Thursday, May 7, 2009 1:11 PM
- Marked as answer by JuergenBeckModerator Friday, May 29, 2009 11:49 AM
Thursday, May 7, 2009 1:11 PMModerator -
Hi Aarch,
If you get you plugin installed I guess your code compiles, is signed and the Execute method being outside the class definition is just a copy-paste error.
I've rewritten the try-catch code block to this:
try { // Create a task activity to follow up with the account customer in 7 days. DynamicEntity followup = new DynamicEntity("task" ); // No need for the next line this is already initialized after calling new DynamicEntity // followup.Properties = new PropertyCollection(); // // assign properties the fast way 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" ] = CrmDateTime.FromUniversal(DateTime.Now.AddDays(7)); followup["scheduledend" ] = CrmDateTime.FromUniversal(DateTime.Now.AddDays(7)); followup["category" ] = context.PrimaryEntityName; // Refer to the new account in the task activity. if (context.OutputParameters.Properties.Contains("id" )) { followup["regardingobjectid" ] = new Lookup("account" , (Guid)context.OutputParameters["Id" ]); } // create task while impersonating the user making the orginal request Guid taskId = context.CreateCrmService(true ).Create(followup); // create task with admin rights (this ensures the task is infact created) Guid taskId = context.CreateCrmService(false ).Create(followup); } catch (System.Web.Services.Protocols.SoapException ex) { throw new InvalidPluginExecutionException("An error occurred in the AccountCreateHandler plug-in." , ex); }
- Edited by IAmNotDrunk Friday, May 8, 2009 12:19 AM spelling
Friday, May 8, 2009 12:18 AM -
Hi
i have edited the lines of code as you said, but still i am getting a generic error after trying to save a newly created account.the error says
"An error has occured
Try this action again.If problem continues,check the Dynamics CRM community for solutions....".
i have signed with strong key also
Thanks, AarchFriday, May 8, 2009 4:37 AM -
Hi Aarch,
Try debugging your plugin
http://code.msdn.microsoft.com/MSCRMPluginDebugger
or do debugging by attaching visual studio debugger to the worker process
or log the error message in a text file to have more understanding of the problem as suggested by above experts
catch (System.Web.Services.Protocols.SoapException ex) { TextWriter log = TextWriter.Synchronized(File.AppendText(@"C:\ErrorLog.txt")); log.WriteLine("Error info" + ex.Detail.InnerText); log.WriteLine("Stack trace" + ex.StackTrace); log.Close(); } catch (Exception ex) { TextWriter log = TextWriter.Synchronized(File.AppendText(@"C:\ErrorLog.txt")); log.WriteLine("Error info" + ex.Message); log.WriteLine("Stack trace" + ex.StackTrace); log.Close(); }
Regards,
Nishant Rana
http://nishantrana.wordpress.com- Marked as answer by JuergenBeckModerator Friday, May 29, 2009 11:50 AM
Friday, May 8, 2009 5:59 AM