views:

1637

answers:

6

Hi

I made a plugin for email entity and registered it on Pre Create event (child pipeline). Plugin is as simple as possible:

public class AddDescription : IPlugin
{
    public void Execute(IPluginExecutionContext context)
    {
        DynamicEntity di = (DynamicEntity)context.InputParameters["Target"];

        di.Properties["description"] = "blabla";
    }
}

But description (=email body) stays the same. No exceptions are thrown. I debuged and it looks like Properties collection is changed ('blabla' description added) but it is not saved.

If I register the same plugin on account entity (Pre Create, child pipeline) it works fine.

Does email entity have any restrictions about changing properties on create?!!?

EDIT (MORE INFO):

I tried to change description, subject, category and subcategory and to my surprise category and subcategory changed while description and subject didn't.

tnx for help bye

+1  A: 

My guess would be that it's because subject and description are attributes shared across all activities (on the activitypointer entity), while category and subcategory are on the email entity.

When you debug, see if there's a property that is another DynamicEntity... this might be where the properties that go to the activity are stored.

Matt
yea that's what I thought after staring into db a few hours.And there is no other parameter in plugin, only DynamicEntity of soon-to-be-created email. And of course you can't create plugin for activity entity.
grega g
+2  A: 

Why are you in the child pipeline? My guess is the base activity is created in the main pipeline and the child activity (as Matt points out - only contains non-shared attributes) then goes through the child pipeline. Does this work as you expect in the parent pipeline? Maybe there's a scenario you have to catch in the child pipeline?

benjynito
yes, it works in parent pipeline, but it doesn't fire when quick campaign or campaign creates emails.
grega g
Could you move to the post-child and create the CRM Service in the child pipeline (google articles on doing this - you can't use the service off of the plugin)? Then do the update that you need?
benjynito
yea that's the only option. However I have to check what happens if there is Exception thrown in Post plugin. Pre plugin cancels operation in this case, I think.
grega g
Yea, I'm not sure if a database transaction is rolled back or not in that case. I'd be interested to hear what you find out.
benjynito
Well, in case of exception transaction is rolled back. Bad news is that in Post Create plugin you cant change anything. I tried replacing description in Properties collection, but no luck. And when I tried to retrieve or update created entity, SQL Exception was thrown.Is there any other Message I could use to change email body. I tried Send, but it doesn't fire on Campaign emails.
grega g
Does the quick campaign just create the e-mails or does it also send them? I'm wondering if you could have a workflow on e-mail create that updates the description.How did you create the (I)CrmService in your Post-Create child pipeline plugin? See http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/a4f98ac6-c7a8-45d0-aaff-1096037b4682. I don't know if that would change the behavior of your update.
benjynito
Update Rollup 6 might fix your issue. http://support.microsoft.com/default.aspx?kbid=970148Find this "Activity entities in Microsoft Dynamics CRM are constructed of a common entity type that is called Activity."
benjynito
yup, it works now (= I can change description property on pre Create child pipleline of email). thank you for all the help.
grega g
Its almost like they were watching ;)
benjynito
A: 

Have anyone got this problem resolution please?

Abish Asharaf
yes. benjynito suggested to update to latest Rollup (at the time 6, now 9) and it worked. See comments of accepted answer.
grega g
A: 

Hi

This is solution.

((DynamicEntity)context.InputParameters.Properties["Target"]).Properties["propertyname"]="propertyvalue";

if this entity does not have this property yu have to add . For example we want to set string property that does not contains target's properties. Tis is the code:

((DynamicEntity)context.InputParameters.Properties["Target"]).Properties.Add(CrmTypes.CreateStringProperty("propertyname", "propertyvalue"));

have nice days.

Ahmet Özgün Özcan
A: 

But yu have to write this code on Pre Plugin. Entity can initialize on pre plugin before event.

Ahmet Özgün Özcan
A: 

Hi, I have the same problem, I have the plug in registered as Create of email in Child Pipeline. If I change the description in that way the activity is updated but I recieve the email without the modifications I made in the body.

((DynamicEntity)context.InputParameters.Properties["Target"]).Properties["propertyname"]="propertyvalue";

Can you help me?

Sebastian