As we all know when a record creation is happening we can find the information of the attributes in that event using Target image from the Pre create event.
You get all the values in the Target image from the Create event.
You get the same image in the update as well. But there is a different.
In update you only get the changed attributes. Not all the attributes of the record. So if you want to get all the attributes of the record you need to do some alternatives.
The best would be to merge the Pre image of the event with the target image.
However please do keep in mind when you are doing that you need to give precedence to the target image and add any attribute that is not in the Target image from the Pre image. If not you will be misguided and will not be able to produce the correct result that you are planning to have.
This blog describes mostly about the work (CRM 365, CRM 2016, CRM 2015, CRM2011, CRM 4.0, CRM 3.0, C#,Javascript and SQL Server) i do.
Showing posts with label Plugins. Show all posts
Showing posts with label Plugins. Show all posts
Tuesday, December 18, 2012
Wednesday, July 11, 2012
Setting the Default Price List for a Product for the first time
When a product is created for the first time the default price list field is disabled. However you can set a value to this by using a javascript.
var lookup = new Object();
var lookupValue = new Array();
lookup.id = “Guid Value”;
lookup.entityType = “pricelevel”;
lookup.name = “Record Name”;
lookupValue[0] = lookup;
Xrm.Page.getAttribute(“pricelevelid”).setValue(lookupValue);
There are very good articles about this which I have given below.
http://mahenderpal.wordpress.com/2011/06/28/set-default-price-list-in-ms-crm-2011-using-java-script/
http://crmbusiness.wordpress.com/2011/02/18/crm-2011-how-to-set-up-a-lookup-using-javascript/
However you might face an issue here as the first time that this fields value is not getting saved to the database. The second time it gets saved.this functionality i have seen only with products. if you save an opportunity you don't get this issue. (If someone has overcome this using javascripts or have done this in any other way than using plugins i would be very much happy to hear about it.)
Is there a way to set the value when the record is saved?.
You cannot use a workflow as the form field is disabled and as you know if a field is disabled on a form then we cannot set a value to it. But using a plugin we can get this done.
We need to use a post create plugin with synchronous mode. I have given below the code for it.
This works correctly and the record is opening with setting a default price list for this field.
public void Execute(IServiceProvider provider)
{
IPluginExecutionContext context = (IPluginExecutionContext)provider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory OrganizationServiceFactory = (IOrganizationServiceFactory)provider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService OrganizationService = OrganizationServiceFactory.CreateOrganizationService(context.UserId);
switch (context.MessageName.ToLower())
{
case "create":
Entity target = context.PostEntityImages["Target"] as Entity;
EntityReference ent = new EntityReference("pricelevel", new Guid("D63F72CC-41CB-E111-B129-080027B1770C"));
target.Attributes.Add("pricelevelid", ent);
OrganizationService.Update(target);
break;
}
}
var lookup = new Object();
var lookupValue = new Array();
lookup.id = “Guid Value”;
lookup.entityType = “pricelevel”;
lookup.name = “Record Name”;
lookupValue[0] = lookup;
Xrm.Page.getAttribute(“pricelevelid”).setValue(lookupValue);
There are very good articles about this which I have given below.
http://mahenderpal.wordpress.com/2011/06/28/set-default-price-list-in-ms-crm-2011-using-java-script/
http://crmbusiness.wordpress.com/2011/02/18/crm-2011-how-to-set-up-a-lookup-using-javascript/
However you might face an issue here as the first time that this fields value is not getting saved to the database. The second time it gets saved.this functionality i have seen only with products. if you save an opportunity you don't get this issue. (If someone has overcome this using javascripts or have done this in any other way than using plugins i would be very much happy to hear about it.)
Is there a way to set the value when the record is saved?.
You cannot use a workflow as the form field is disabled and as you know if a field is disabled on a form then we cannot set a value to it. But using a plugin we can get this done.
We need to use a post create plugin with synchronous mode. I have given below the code for it.
This works correctly and the record is opening with setting a default price list for this field.
public void Execute(IServiceProvider provider)
{
IPluginExecutionContext context = (IPluginExecutionContext)provider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory OrganizationServiceFactory = (IOrganizationServiceFactory)provider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService OrganizationService = OrganizationServiceFactory.CreateOrganizationService(context.UserId);
switch (context.MessageName.ToLower())
{
case "create":
Entity target = context.PostEntityImages["Target"] as Entity;
EntityReference ent = new EntityReference("pricelevel", new Guid("D63F72CC-41CB-E111-B129-080027B1770C"));
target.Attributes.Add("pricelevelid", ent);
OrganizationService.Update(target);
break;
}
}
Tuesday, July 5, 2011
Difference between Parent and Child Pipelines
We see this a lot when we publish plugins through the plugin deployer. We don't tend to notice this as we most of the time user Parent pipeline. But why there is another Pipe Line.
The reason for this is simple.
If you open the entity from CRM without going to it from another CRM record this would be the parent pipe line.
If you go to the same entity record through another entities record it would be the child pipe line.
If you have written a plugin for a particular entity and have used the parent pipe line then it would not fire id the same scenario happens if you have to come the record through another record.
There is a very nice article about this written in the following web link. This helped me too to understand the difference. This was given to me by a colleague of mine.
http://crmscape.blogspot.com/2009/02/ms-crm-40-plug-in-stages-pipelines-and.html
The reason for this is simple.
If you open the entity from CRM without going to it from another CRM record this would be the parent pipe line.
If you go to the same entity record through another entities record it would be the child pipe line.
If you have written a plugin for a particular entity and have used the parent pipe line then it would not fire id the same scenario happens if you have to come the record through another record.
There is a very nice article about this written in the following web link. This helped me too to understand the difference. This was given to me by a colleague of mine.
http://crmscape.blogspot.com/2009/02/ms-crm-40-plug-in-stages-pipelines-and.html
Tuesday, December 14, 2010
Plugin Event - Associate and Disassociate Records
There is no plugin event for the association and disassociation events.
However there is a workaround for this in the below URL.
http://www.avanadeblog.com/xrm/2010/05/i-find-your-lack-of-events-disturbing.html
However there is a workaround for this in the below URL.
http://www.avanadeblog.com/xrm/2010/05/i-find-your-lack-of-events-disturbing.html
Monday, June 7, 2010
Publishing workflows.
When publishing workflows please check the scope of the workflow. It has 4 types.
• User – will only run for the user who has created the workflow
• BU – Will only run for the BU that the user is in
• Parent- Child - Will only run for the BU that the user is in and the parent BU
• Organization – will run for the whole organization.
• User – will only run for the user who has created the workflow
• BU – Will only run for the BU that the user is in
• Parent- Child - Will only run for the BU that the user is in and the parent BU
• Organization – will run for the whole organization.
Thursday, April 1, 2010
Multi Purpose Workflow
Is it possible to write a workflow that can be triggered for many entities in CRM.
The answer is yes. You can do that.
Rather than writing several workflows to get this done you can write one workflow and then use a variable for flag here.
I have listed below a sample workflow.
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
try
{
Guid ID1 = ((SDK.Lookup)base.GetValue(ID1Property)).Value;
string Type = ((String)base.GetValue(TypeProperty));
Guid _iID = Guid.Empty;
switch (Type)
{
case "1":
_iID = ((SDK.Lookup)base.GetValue(iIDProperty)).Value;
break;
case "2":
_iID = ((SDK.Lookup)base.GetValue(pIDProperty)).Value;
break;
case "3":
_iID = ((SDK.Lookup)base.GetValue(qIDProperty)).Value;
break;
case "4":
_iID = ((SDK.Lookup)base.GetValue(fIDProperty)).Value;
break;
}
IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
IWorkflowContext context = contextService.Context;
}
catch (Exception ex)
{
}
return ActivityExecutionStatus.Closed;
}
as for this example we need to create 4 dependency properties. they are
iIDProperty, pIDProperty, qIDProperty, fIDProperty.
depending on what we get for the switch statement the relevant dependency property would get updated.
The answer is yes. You can do that.
Rather than writing several workflows to get this done you can write one workflow and then use a variable for flag here.
I have listed below a sample workflow.
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
try
{
Guid ID1 = ((SDK.Lookup)base.GetValue(ID1Property)).Value;
string Type = ((String)base.GetValue(TypeProperty));
Guid _iID = Guid.Empty;
switch (Type)
{
case "1":
_iID = ((SDK.Lookup)base.GetValue(iIDProperty)).Value;
break;
case "2":
_iID = ((SDK.Lookup)base.GetValue(pIDProperty)).Value;
break;
case "3":
_iID = ((SDK.Lookup)base.GetValue(qIDProperty)).Value;
break;
case "4":
_iID = ((SDK.Lookup)base.GetValue(fIDProperty)).Value;
break;
}
IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
IWorkflowContext context = contextService.Context;
}
catch (Exception ex)
{
}
return ActivityExecutionStatus.Closed;
}
as for this example we need to create 4 dependency properties. they are
iIDProperty, pIDProperty, qIDProperty, fIDProperty.
depending on what we get for the switch statement the relevant dependency property would get updated.
CRM 4 N: N Plugin
It’s been a very long time since I have posted anything. I (and our team) have been very busy with a project going on. However there is couple of new things that I have found in CRM that I thought of sharing with you.
You might know this, you might not know this “We cannot write a plugin or a workflow for CRM N: N (many to many) relationship.” This might cause you a lot of issues and when a new record is added to such a relationship you might want to trigger some other event. We certainly came across that situation and tried everything to no avail. Then we found an unsupported customization which was published in Google by Aaron. That was very very helpful. I have pasted the link below.
http://consulting.ascentium.com/blog/crm/Post533.aspx
What we do here is enable both “Association” and “Disassociation” SDK message to the plugin registration tool. Also when enabling this, it would act as a generic plugin which would get fired for the entire N: N relationships in CRM. This is handy. I’m sure that with CRM 5, dynamics team would add this facility also. But for the time being we might have to live with this solution.
After registering the plugin the code needed to capture information is also pasted below. Whatever is here is an extended version of what was pasted in the above link. Thanks again to Aaron.
protected override void PostAssociateEntities(IPluginExecutionContext context)
{
TextWriter textWriter = TextWriter.Synchronized(File.AppendText(@"C:\Temp\PostAssociateEntities.txt"));
if (context.MessageName == "AssociateEntities")
{
if (context.InputParameters.Contains("Moniker1"))
{
Moniker EntityMoniker = (Moniker)context.InputParameters["Moniker1"];
Guid Moniker1 = EntityMoniker.Id;
string Name = EntityMoniker.Name;
textWriter.WriteLine(EntityMoniker.Id.ToString());
textWriter.WriteLine(EntityMoniker.Name.ToString());
}
if (context.InputParameters.Contains("Moniker2"))
{
Moniker EntityMoniker = (Moniker)context.InputParameters["Moniker2"];
textWriter.WriteLine(EntityMoniker.Id.ToString());
textWriter.WriteLine(EntityMoniker.Name.ToString());
}
textWriter.Close();
}
}
You might know this, you might not know this “We cannot write a plugin or a workflow for CRM N: N (many to many) relationship.” This might cause you a lot of issues and when a new record is added to such a relationship you might want to trigger some other event. We certainly came across that situation and tried everything to no avail. Then we found an unsupported customization which was published in Google by Aaron. That was very very helpful. I have pasted the link below.
http://consulting.ascentium.com/blog/crm/Post533.aspx
What we do here is enable both “Association” and “Disassociation” SDK message to the plugin registration tool. Also when enabling this, it would act as a generic plugin which would get fired for the entire N: N relationships in CRM. This is handy. I’m sure that with CRM 5, dynamics team would add this facility also. But for the time being we might have to live with this solution.
After registering the plugin the code needed to capture information is also pasted below. Whatever is here is an extended version of what was pasted in the above link. Thanks again to Aaron.
protected override void PostAssociateEntities(IPluginExecutionContext context)
{
TextWriter textWriter = TextWriter.Synchronized(File.AppendText(@"C:\Temp\PostAssociateEntities.txt"));
if (context.MessageName == "AssociateEntities")
{
if (context.InputParameters.Contains("Moniker1"))
{
Moniker EntityMoniker = (Moniker)context.InputParameters["Moniker1"];
Guid Moniker1 = EntityMoniker.Id;
string Name = EntityMoniker.Name;
textWriter.WriteLine(EntityMoniker.Id.ToString());
textWriter.WriteLine(EntityMoniker.Name.ToString());
}
if (context.InputParameters.Contains("Moniker2"))
{
Moniker EntityMoniker = (Moniker)context.InputParameters["Moniker2"];
textWriter.WriteLine(EntityMoniker.Id.ToString());
textWriter.WriteLine(EntityMoniker.Name.ToString());
}
textWriter.Close();
}
}
Sunday, August 16, 2009
Plugin Execution - Post Plugins
With CRM4 most of the time we face that the pre plugins are running smoothly. But the post plugins are not running. We check our code to see whether there are any issues with what we have coded. Seems everything is correct and the plug in should run smoothly.
Then only we check whether the asynce service is running and then only we find out that is has been stopped. This is not the same case in CRM3 as both pre and post call outs are running from the workflow service. So if your pre plugin is running but the post async plugins are not running the first thing you should check is the microsoft async service.
Then only we check whether the asynce service is running and then only we find out that is has been stopped. This is not the same case in CRM3 as both pre and post call outs are running from the workflow service. So if your pre plugin is running but the post async plugins are not running the first thing you should check is the microsoft async service.
Friday, November 14, 2008
CRM Callouts
One thing i learn the hard way about callous is that if you trying to update the same entity in a call out you should always use the pre callouts instead of post call outs. although using post callouts seems to work nicely you will get in to errors when you go live.
If you are using to update the same entity use pre call outs.
if it's a different entity use post cal outs.
If you are using to update the same entity use pre call outs.
if it's a different entity use post cal outs.
Subscribe to:
Posts (Atom)
Retrieving Calendar of a Bookable Resource in Dynamics
There are occasions where we need to retrieve working days and working times of a resource in Dynamics grammatically. This is quite possible...