locked
Plugin for appointment PreStage RRS feed

  • Question

  • Ok, so I've got a question that I've been racking my brain and google for an answer to for about 4 hours now.

    I have a plugin, it generates a guid and writes over the ID of the entity and it runs on the PreStage of the entity.  It then builds an HTML tag and stores it in a field to have an embedded link directly to the entity.  The plugin's code is

    public class Plugin : IPlugin
    
    	{
    
    		private string crmSite = "http://<SERVERNAME>/activities/appointment/edit.aspx?id=";
    
    		private string crmLinkStart = "<a href='";
    
    		private string crmLinkMiddle = "'>";
    
    		private string crmLinkTrailer = "</a>";
    
    		private string GUIDfield = "activityid";
    
    		private string OutputField = "new_urllink";
    
    		private string nameField = "subject";
    
    		//private string mode = "URL";
    
    		private string mode = "HTML";
    
    
    
    		public void Execute(IPluginExecutionContext context)
    
    		{
    
    			try
    
    			{
    
    				GUIDMethodPre(context);
    
    			}
    
    			catch (Microsoft.Crm.Sdk.InvalidPluginExecutionException ex)
    
    			{
    
    				throw new InvalidPluginExecutionException(ex.Message);
    
    			}
    
    		}
    
    
    
    		public void GUIDMethodPre(IPluginExecutionContext context)
    
    		{
    
    			if ((context.InputParameters.Properties.Contains(ParameterName.Target) && (context.InputParameters.Properties[ParameterName.Target] is DynamicEntity)))
    
    			{
    
    				DynamicEntity _dentity = (DynamicEntity)context.InputParameters[ParameterName.Target];
    
    				switch (context.MessageName)
    
    				{
    
    					case MessageName.Create:
    
    						//Generates a GUID to assign to the entity
    
    						Guid _accountguid = Guid.NewGuid();
    
    						Key _accountkey = new Key(_accountguid);
    
    						KeyProperty _keyprop = new KeyProperty(GUIDfield, _accountkey);
    
    						_dentity.Properties.Add(_keyprop);
    
    						Key _keyproperty = (Key)_dentity[GUIDfield];
    
    
    
    						string url;
    
    						if (mode == "HTML")
    
    						{
    
    							string orgName = _dentity.Properties[nameField].ToString();
    
    							url = crmLinkStart + crmSite + _keyproperty.Value.ToString() + crmLinkMiddle + orgName + crmLinkTrailer;
    
    						}
    
    						else
    
    						{
    
    							url = crmSite + _keyproperty.Value.ToString();
    
    						}
    
    
    
    						StringProperty _url = new StringProperty(OutputField, url);
    
    						_dentity.Properties.Add(_url);
    
    
    
    						context.InputParameters[ParameterName.Target] = _dentity;
    
    						break;
    
    					case MessageName.Update:
    
    						break;
    
    
    
    					case MessageName.Delete:
    
    						break;
    
    				}
    
    			}
    
    		}
    
    }
    
    


    I have used this plugin on the account, contact, email, phone call, task, opportunity, lead, and fax.  I have registered it and it works.  When I register it the exact same way I did before for the appointment entity, it doesn't do anything.  I tried to debug it and apparently it doesn't seem to even be executing.

    Is there something different about the Create event for the Appointment entity, should I be using a different message?

    • Moved by Donna EdwardsMVP Wednesday, July 15, 2009 1:37 PM (From:CRM Deployment)
    Tuesday, May 12, 2009 4:04 PM

Answers

  • Try registering the plugin on the child pipeline, not the parent pipeline. Activities seem to be handled somewhat differently to other entities with respect to the plugin pipeline
    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk
    Wednesday, May 13, 2009 7:55 AM
    Moderator

All replies

  • Try registering the plugin on the child pipeline, not the parent pipeline. Activities seem to be handled somewhat differently to other entities with respect to the plugin pipeline
    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk
    Wednesday, May 13, 2009 7:55 AM
    Moderator
  • I just tried registering it in the child pipeline and CRM is giving me a scheduler engine failure error.  I did some reading and it looks like its having problems firing this because its trying to execute this code, while the scheduler is trying to do its part.  At least that's my theory.

    The stuff I found said this needs to be done Asynchronously to prevent that but you can't execute events  Asynchronously and have them in the prestage, they have to be post.

    Any thoughts?
    Wednesday, May 13, 2009 12:38 PM