2

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

grega g
  • 1,079
  • 1
  • 12
  • 25

3 Answers3

2

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?

John Hoven
  • 4,085
  • 2
  • 28
  • 32
  • yes, it works in parent pipeline, but it doesn't fire when quick campaign or campaign creates emails. – grega g Aug 20 '09 at 06:40
  • 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? – John Hoven Aug 20 '09 at 14:31
  • 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 Aug 21 '09 at 12:37
  • 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. – John Hoven Aug 21 '09 at 13:43
  • 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 Aug 26 '09 at 12:18
  • 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. – John Hoven Aug 26 '09 at 14:02
  • 1
    Update Rollup 6 might fix your issue. http://support.microsoft.com/default.aspx?kbid=970148 Find this "Activity entities in Microsoft Dynamics CRM are constructed of a common entity type that is called Activity." – John Hoven Aug 27 '09 at 21:02
  • yup, it works now (= I can change description property on pre Create child pipleline of email). thank you for all the help. – grega g Aug 28 '09 at 07:11
  • Its almost like they were watching ;) – John Hoven Aug 28 '09 at 12:42
1

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
  • 4,656
  • 1
  • 22
  • 32
  • 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 Aug 19 '09 at 07:36
0

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"));
ForceMagic
  • 6,230
  • 12
  • 66
  • 88