0
votes

I create a new plugin for dynamic CRM 2011 for a costume Activity Entity.

this new activity have "to" field like Email and some other activities.

plugin are working on Create and Update steps for activity.

my problem is when i want to get "to" field value the below line of code return false value and i don't know what i have done. in fact i can fetch other custom field and just the "to" field does not work.

if (entity3.Attributes.Contains("to"))

and this is whole code:

public void Execute(IServiceProvider serviceProvider)
{
    if (serviceProvider == null)
    {
        throw new ArgumentNullException("serviceProvider");
    }

    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    if (context.InputParameters.Contains("Target") && (context.InputParameters["Target"] is Entity))
    {
            Entity entity2 = (Entity)context.InputParameters["Target"];
            if (entity2.LogicalName == "EntityAtivity")
            {
                QueryExpression expression3 = new QueryExpression("EntityAtivity");
                ColumnSet set2 = new ColumnSet();
                set2.AllColumns = true;
                expression3.ColumnSet = set2;
                ConditionExpression item = new ConditionExpression();
                item.AttributeName = "activityid";
                CurrentGuid = (Guid)entity2.Attributes["activityid"];
                item.Values.Add(this.CurrentGuid);
                FilterExpression expression5 = new FilterExpression();
                expression5.Conditions.Add(item);
                expression3.Criteria = expression5;
                EntityCollection entitys2 = service.RetrieveMultiple(expression3);
                foreach (Entity entity3 in entitys2.Entities)
                {
                    this.dbGuid = (Guid)entity3.Attributes["activityid"];
                    if (entity3.Attributes.Contains("to"))
                    {
                        try
                        {
                            foreach (Entity entity10 in ((EntityCollection)entity3.Attributes["to"]).Entities)
                            {
                                this.dbTo.Add(((EntityReference)entity10.Attributes["partyid"]).LogicalName);
                                this.dbToId.Add(((EntityReference)entity10.Attributes["partyid"]).Id);
                            }
                        }
                        catch (Exception)
                        {
                            this.dbTo.Clear();
                        }
                    }
                } // foreach
            }//if (entity2.LogicalName == "EntityAtivity")
    }//if (context.InputParameters.Contains("Target") && (context.InputParameters["Target"] is Entity))
}

any know what i should done to correct plugin?

2
EntityAtivity isn't a valid name for the entity. When coding it uses the logical name which is all lower case and starts with your prefix like 'new_'. When retrieving values from the record the plugin is firing on you should use the Target input parameter, or register Pre & Post entity images. - Andy Meyers
EntityActivity is just a sample name. i use preimage but i face new error: Entity preEntity = (Entity)context.PreEntityImages.["PreImage"]; is it correct? - Aqil
The PreImage and PostImage names are registered via the plugin tool. You can choose which images you want, what the name is, and what fields are available in them. - Andy Meyers
andy meyers: tanks. i solve it. thanks to help me. - Aqil

2 Answers

0
votes

Your question and answer is hard to understand because your English could use some work, but I believe your issue is that you're looking for an attribute in the target of a value that hasn't been set. If an attribute hasn't been set or updated, it will not show up in the target of the the plugin. As @AndyMeyers says, you should use the PreImage and PostImage images to define what attributes you always want to be included in the processing of your plugin.

0
votes

So i solve my problem. i create 2 steps, for Create and Update.

when i disable the Create Step and create pre image for update step, plug in fetch to field and show the values.