Working in Dynamics 365 doing plugin development was problematic yesterday. I've seen more than one occasion now where I can't get a plugin to work properly and there is no obvious reason why. It turned out that uninstalling and reinstalling the plugin profiler solution fixed the issue with no code change.
The profiler must be caching something......
I hope this helps someone else and I am not the only person seeing this wonky behavior!
Showing posts with label Plug-in. Show all posts
Showing posts with label Plug-in. Show all posts
Friday, August 25, 2017
Plugin Profiler Causing Problems
Labels:
.NET,
CRM Online,
Dynamics 365,
Microsoft Dynamics CRM,
Plug-in,
Plugins
Wednesday, November 9, 2011
How To Trigger a Plug-in From JScript in Microsoft Dynamics CRM
From my time in the Microsoft Dynamics CRM forums, I can tell you that the question of how to trigger a plug-in from jscript comes up pretty frequently. Usually someone wants to just trigger the plug-in from a form event, but also sometimes people want to trigger the plug-in from a ribbon button. Unfortunately, a lot of the replies usually say that it's not supported or not possible. I am happy to say that it is possible and that I have regularly used this workaround to achieve this and it even uses supported methodology.
The code examples I link to today will be for CRM 2011 but the basic methodology is the same for 4.0 also.
Here is how this works:
1. First you need to create a new custom entity to act as a trigger entity, I'll often times even name this new custom entity "new_trigger{plugin name}"
2. Now you must register your plug-in (or several plug-ins) on the create or update messages for this new entity. (I usually prefer the create message for my registrations because a new record will be created which keeps a record or audit-trail of who manually executed your plug-in and when in the created by and created time-stamp attributes on the entity)
3. You must create a jscript web resource that contains a function that performs a soap update or create call on the entity depending on which message you registered your plug-in on.
4. Lastly you must add your web resource to your form and call your update or create jscript function on one of the exposed form events (OnLoad, OnSave, etc...). You can also call your jscript function from ribbon button if you want.
The code examples I link to today will be for CRM 2011 but the basic methodology is the same for 4.0 also.
Here is how this works:
1. First you need to create a new custom entity to act as a trigger entity, I'll often times even name this new custom entity "new_trigger{plugin name}"
2. Now you must register your plug-in (or several plug-ins) on the create or update messages for this new entity. (I usually prefer the create message for my registrations because a new record will be created which keeps a record or audit-trail of who manually executed your plug-in and when in the created by and created time-stamp attributes on the entity)
3. You must create a jscript web resource that contains a function that performs a soap update or create call on the entity depending on which message you registered your plug-in on.
4. Lastly you must add your web resource to your form and call your update or create jscript function on one of the exposed form events (OnLoad, OnSave, etc...). You can also call your jscript function from ribbon button if you want.
I hope this helps!
-
Sunday, April 17, 2011
Instantiating a Service Object Within a Plug-in in Microsoft Dynamics CRM 2011
I have seen people asking lately in the forums about how to instantiate a service reference from within a plug-in / plugin. I whipped up a quick example the other day. I will show you how to do it and work with an entity without generating early bound types or specific proxies, but I will also provide a link below to a walk-through on how to go that route also. This example uses the Entity class from the CRM SDK. It is the equivalent to DynamicEntity in CRM 4.0. It is nice because you can dynamically work with entities without having generated the specific proxy information for your organization's metadata.
First, here is a simple plugin example that instantiates a service object in the simplest way. The example then uses the exposed context UserID to perform a retrievemultiple request on a systemuser and adds the user fullname attribute to the contact entity that is the target of the plug-in execution. Don't ask why I am putting this info into the address1_city as this is just a simple proof of concept. This example is intended to be registered pre-operation on the contact entity.
Also, here is a walk-through on working with the early-bound entity types in a plug-in:
http://msdn.microsoft.com/en-us/library/gg695782.aspx
First, here is a simple plugin example that instantiates a service object in the simplest way. The example then uses the exposed context UserID to perform a retrievemultiple request on a systemuser and adds the user fullname attribute to the contact entity that is the target of the plug-in execution. Don't ask why I am putting this info into the address1_city as this is just a simple proof of concept. This example is intended to be registered pre-operation on the contact entity.
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the organization service reference.
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
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 parmameters.
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "contact")
{
if (entity.Attributes.Contains("address1_city") == false)
{
RetrieveMultipleRequest rmreq = new RetrieveMultipleRequest();
RetrieveMultipleResponse rmresp = new RetrieveMultipleResponse();
QueryExpression query = new QueryExpression()
{
EntityName = "systemuser",
ColumnSet = new ColumnSet(true),
Criteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression
{
AttributeName = "systemuserid",
Operator = ConditionOperator.Equal,
Values = { context.UserId.ToString() }
}
}
}
};
rmreq.Query = query;
rmresp = (RetrieveMultipleResponse)service.Execute(rmreq);
Entity user = (Entity)rmresp.EntityCollection.Entities[0];
entity.Attributes.Add("address1_city", context.UserId.ToString() + ": " + user.Attributes["fullname"]);
}
else
{
// Throw an error, because account numbers must be system generated.
// Throwing an InvalidPluginExecutionException will cause the error message to be displayed in a dialog of the Web application.
throw new InvalidPluginExecutionException("Bad, Naughty Plug-in, Don't do that!.");
}
}
}
}
Also, here is a walk-through on working with the early-bound entity types in a plug-in:
http://msdn.microsoft.com/en-us/library/gg695782.aspx
Subscribe to:
Posts (Atom)