Question

I am creating a plugin on Disassociate message of Project (custom entity); having N:N relationship with User entity. It's not working. Here is the code.

        IOrganizationService service = localContext.OrganizationService;
        IPluginExecutionContext context = localContext.PluginExecutionContext;

        // Get Primary Entity
        EntityReference target = (EntityReference)context.InputParameters["Target"];

        if (target.LogicalName == "new_project" || target.LogicalName == "systemuser")
        {
            Relationship relationShip = (Relationship)context.InputParameters["Relationship"];

            // Get Related Entities
            EntityReferenceCollection relatedentities = (EntityReferenceCollection)context.InputParameters["RelatedEntities"];
            foreach (EntityReference rel in relatedentities)
            {
                // Check Related Entity Logical & Schema name
                if (rel.LogicalName == "new_project" && relationShip.SchemaName == "new_systemuser_new_project")
                {
                    Entity user = service.Retrieve("systemuser", target.Id, new ColumnSet(true));
                    Entity project = service.Retrieve("new_project", rel.Id, new ColumnSet(true));

                    // Grant access
                    RevokeAccessRequest revokeAccessRequest = new RevokeAccessRequest
                    {
                       Revokee=target,
                        Target = rel
                    };

                    service.Execute(revokeAccessRequest);
                }
            }
        }

But I am not able to debug this plugin using plugin registration tool.It returns the message "App Domain Unloaded".

enter image description here

I don't know what is wrong with this plugin. Please Help.

Was it helpful?

Solution

I have solved this problem. I had registered this plugin in update message, then changed RegisterFile.crmregister

MessageName="Disassociate" and PrimaryEntityName=""

also changed the default constructor of the my plugin class.

base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(10, "Disassociate", "", new Action<LocalPluginContext>(ExecutePreValidateProjectUpdate)));

Hope this will help someone facing same problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top