grega g
grega g

Reputation: 1089

MS CRM - Pre Create plugin doesn't change property value

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

Upvotes: 2

Views: 7856

Answers (3)

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"));

Upvotes: 0

John Hoven
John Hoven

Reputation: 4085

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?

Upvotes: 2

Matt
Matt

Reputation: 4686

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.

Upvotes: 1

Related Questions