Archive

Posts Tagged ‘assign’

[Code Snippet] Dynamics Post Assign Plugin

This article is a response to one of the blog questions. 

Below is the code snippet for Post Assign (i.e., Ownership change) plug-in.

In the ‘Post Assign’ plug-in you get 2

  • Current record as ‘Entity Reference’ in ‘Target‘ attribute.
  • Records new Owner (i.e., Owner or Team) in the ‘Assignee‘ attribute.

EntityReference entRefCurrentRecord = null;
EntityReference entRefAssignee = null;

// Get current record as Entity Reference
if ((context.InputParameters.Contains(“Target”)) && (context.InputParameters[“Target”] is EntityReference))
{
entRefCurrentRecord = (EntityReference)context.InputParameters[“Target“];
}

// Get User/Team whom the record assigned to from ‘Assignee’ property of Context
if ((context.InputParameters.Contains(“Assignee”)) && (context.InputParameters[“Assignee”] is EntityReference))
{
entRefAssignee = (EntityReference)context.InputParameters[“Assignee“];
}

// Write your business logic

  • You might want to register Pre/Post images on the Plug-in step, to read other attributes of the record.

🙂

Advertisement
Categories: CRM Tags: , ,

Plug-in on related entities during ‘Cascade All’ actions

Assume the relationship behavior between ‘Contact’ and ‘Appointment’ is “Cascade All” on ‘Assign’ action.

Relationship Behavior

Relationship Behavior – Assign – Cascade All

By virtue of that, if a Contact has 2 Appointments, if I change the owner of ‘Contact’ the related 2 Appointment owner also changes.

In one of the requirement, we have to restrict the Cascade operation based on business logic on child record (i.e.,  Appointment)

So I registered a Plugin on ‘Assign’ of ‘Appointment’ and want to handle the Cascade operation, but the Plugin never get executed.

Reason & Solution

  • CRM treats Cascade Assign operation on Child records as an Update.
  • Register the Plug-in on ‘Update’ instead of ‘Assign’ message.
  • In the Update plug-in, the Target entity only contain ‘Owner’ field

🙂