Asked by:
Task and Phone Activity Created through the Social Pane CRM 2013

Question
-
Hi there,
I have a plugin customization that updates the organization field on the activity
entity if the Regarding field has a parent organization. The plugin gets fired
on the PostCreate and looks for if the Regarding Object Id is populated and
then gets parent organization id and populates the activity entity. The plugin
works fine when creating Task, Phone from Activity Form but not from the Social
Pane on the Contact entity. My plugin is looking for regardingobjectid
field. When Task or Phone Activities are created from the Social Pane it looks
like the regardingobjectid is not been passed in the CRM pipeline.What am I
missing? Here is my plugin codeprivate
static string Customer = "regardingobjectid";
private static string ParentCustomer =
"my_organizationid";
public override void HandleAfterOpCreate()
{
try
{
if (!
(this.PluginExecutionContext.PrimaryEntityName.ToLower().Equals(Xrm.Task.EntityLogicalName)
||
this.PluginExecutionContext.PrimaryEntityName.ToLower().Equals(Xrm.PhoneCall.EntityLogicalName)
||
this.PluginExecutionContext.PrimaryEntityName.ToLower().Equals(Xrm.Email.EntityLogicalName)
||
this.PluginExecutionContext.PrimaryEntityName.ToLower().Equals(Xrm.Appointment.EntityLogicalName)))
return;
base.HandleAfterOpCreate();
if (this.PluginExecutionContext.MessageName
== MessageName.Create)
{
if
(this.InputTargetEntity.Contains(Customer))
{
var
id = this.OutputID;
var
customerId = ((EntityReference)this.InputTargetEntity.Attributes[Customer]).Id;
ActivityService.UpdateActivity(id, customerId, this.OrganizationService,
this.TracingService, this.PluginExecutionContext.PrimaryEntityName.ToLower());
}
}
}
catch (Exception ex)
{
this.TracingService.Trace(this.ToString() + " {0}",
"Exception: {0}", ex.ToString());
throw;
}
}- Edited by SPCRM2011 Thursday, March 6, 2014 5:10 PM
Thursday, March 6, 2014 5:08 PM
All replies
-
Hi,
Is the plugin throwing any error?
- Swaroop
Thursday, March 6, 2014 7:40 PM -
No error. Below are the attributes been passed into CRM on Stage 40 and there is no reference of regardingobjectid. So not sure why Microsoft is doing things differently from the Social Pane.
<MyPluginContext xmlns="http://schemas.datacontract.org/2004/07/SerializePluginContext" xmlns:i="<BusinessUnitId>bbc3c04d-654d-e311-9b5e-0050569e3609</BusinessUnitId><CorrelationId>044e7768-51f2-4f58-8a0c-ce6ba352d3d2</CorrelationId><Depth>1</Depth><InitiatingUserId>4a4db552-6d4d-e311-a499-0050569e3609</InitiatingUserId><InputParameters">http://www.w3.org/2001/XMLSchema-instance"><BusinessUnitId>bbc3c04d-654d-e311-9b5e-0050569e3609</BusinessUnitId><CorrelationId>044e7768-51f2-4f58-8a0c-ce6ba352d3d2</CorrelationId><Depth>1</Depth><InitiatingUserId>4a4db552-6d4d-e311-a499-0050569e3609</InitiatingUserId><InputParameters xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="Targethttp://schemas.datacontract.org/2004/07/System.Collections.Generic"><a:KeyValuePairOfstringanyType><b:key>Target</b:key><b:value i:type="a:Entity"><a:Attributes><a:KeyValuePairOfstringanyType><b:key>activityid</b:key><b:value i:type="c:guid" xmlns:c="d9bc28a5-54a5-e311-98bb-0050569e3609createdbyhttp://schemas.microsoft.com/2003/10/Serialization/">d9bc28a5-54a5-e311-98bb-0050569e3609</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>createdby</b:key><b:value i:type="a:EntityReference"><a:Id>4a4db552-6d4d-e311-a499-0050569e3609</a:Id><a:LogicalName>systemuser</a:LogicalName><a:Name i:nil="true"/></b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>owningbusinessunit</b:key><b:value i:type="a:EntityReference"><a:Id>bbc3c04d-654d-e311-9b5e-0050569e3609</a:Id><a:LogicalName>businessunit</a:LogicalName><a:Name i:nil="true"/></b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>modifiedon</b:key><b:value i:type="c:dateTime" xmlns:c="2014-03-06T17:27:52Zmodifiedonbehalfbyhttp://www.w3.org/2001/XMLSchema">2014-03-06T17:27:52Z</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>modifiedonbehalfby</b:key><b:value i:nil="true"/></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>statecode</b:key><b:value i:type="a:OptionSetValue"><a:Value>0</a:Value></b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>statuscode</b:key><b:value i:type="a:OptionSetValue"><a:Value>2</a:Value></b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>subject</b:key><b:value i:type="c:string" xmlns:c="Where">http://www.w3.org/2001/XMLSchema">Where is the Regarding Object Id</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>scheduledend</b:key><b:value i:type="c:dateTime" xmlns:c="2014-03-11T04:00:00Ztimezoneruleversionnumberhttp://www.w3.org/2001/XMLSchema">2014-03-11T04:00:00Z</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>timezoneruleversionnumber</b:key><b:value i:type="c:int" xmlns:c="0isworkflowcreatedhttp://www.w3.org/2001/XMLSchema">0</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>isworkflowcreated</b:key><b:value i:type="c:boolean" xmlns:c="falseactivitytypecodehttp://www.w3.org/2001/XMLSchema">false</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>activitytypecode</b:key><b:value i:type="c:string" xmlns:c="taskscheduleddurationminuteshttp://www.w3.org/2001/XMLSchema">task</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>scheduleddurationminutes</b:key><b:value i:type="c:int" xmlns:c="0actualstarthttp://www.w3.org/2001/XMLSchema">0</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>actualstart</b:key><b:value i:type="c:dateTime" xmlns:c="2014-03-06T17:27:52Zisregularactivityhttp://www.w3.org/2001/XMLSchema">2014-03-06T17:27:52Z</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>isregularactivity</b:key><b:value i:type="c:boolean" xmlns:c="truemodifiedbyhttp://www.w3.org/2001/XMLSchema">true</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>modifiedby</b:key><b:value i:type="a:EntityReference"><a:Id>4a4db552-6d4d-e311-a499-0050569e3609</a:Id><a:LogicalName>systemuser</a:LogicalName><a:Name i:nil="true"/></b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>isbilled</b:key><b:value i:type="c:boolean" xmlns:c="falseprioritycodehttp://www.w3.org/2001/XMLSchema">false</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>prioritycode</b:key><b:value i:type="a:OptionSetValue"><a:Value>1</a:Value></b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>createdon</b:key><b:value i:type="c:dateTime" xmlns:c="2014-03-06T17:27:52Zowneridhttp://www.w3.org/2001/XMLSchema">2014-03-06T17:27:52Z</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>ownerid</b:key><b:value i:type="a:EntityReference"><a:Id>4a4db552-6d4d-e311-a499-0050569e3609</a:Id><a:LogicalName>systemuser</a:LogicalName><a:Name i:nil="true"/></b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>scheduledstart</b:key><b:value i:type="c:dateTime" xmlns:c="2014-03-11T04:00:00Zhttp://www.w3.org/2001/XMLSchema">2014-03-11T04:00:00Z</b:value></a:KeyValuePairOfstringanyType></a:Attributes><a:EntityState i:nil="true"/><a:FormattedValues><a:KeyValuePairOfstringstring><b:key>modifiedon</b:key><b:value>2014-03-06T12:27:52-05:00</b:value></a:KeyValuePairOfstringstring><a:KeyValuePairOfstringstring><b:key>statecode</b:key><b:value>Open</b:value></a:KeyValuePairOfstringstring><a:KeyValuePairOfstringstring><b:key>statuscode</b:key><b:value>Not Started</b:value></a:KeyValuePairOfstringstring><a:KeyValuePairOfstringstring><b:key>scheduledend</b:key><b:value>2014-03-11T00:00:00-04:00</b:value></a:KeyValuePairOfstringstring><a:KeyValuePairOfstringstring><b:key>timezoneruleversionnumber</b:key><b:value>0</b:value></a:KeyValuePairOfstringstring><a:KeyValuePairOfstringstring><b:key>isworkflowcreated</b:key><b:value>No</b:value></a:KeyValuePairOfstringstring><a:KeyValuePairOfstringstring><b:key>activitytypecode</b:key><b:value>Task</b:value></a:KeyValuePairOfstringstring><a:KeyValuePairOfstringstring><b:key>scheduleddurationminutes</b:key><b:value>0</b:value></a:KeyValuePairOfstringstring><a:KeyValuePairOfstringstring><b:key>actualstart</b:key><b:value>2014-03-06T12:27:52-05:00</b:value></a:KeyValuePairOfstringstring><a:KeyValuePairOfstringstring><b:key>isregularactivity</b:key><b:value>Yes</b:value></a:KeyValuePairOfstringstring><a:KeyValuePairOfstringstring><b:key>isbilled</b:key><b:value>No</b:value></a:KeyValuePairOfstringstring><a:KeyValuePairOfstringstring><b:key>prioritycode</b:key><b:value>Normal</b:value></a:KeyValuePairOfstringstring><a:KeyValuePairOfstringstring><b:key>createdon</b:key><b:value>2014-03-06T12:27:52-05:00</b:value></a:KeyValuePairOfstringstring><a:KeyValuePairOfstringstring><b:key>scheduledstart</b:key><b:value>2014-03-11T00:00:00-04:00</b:value></a:KeyValuePairOfstringstring></a:FormattedValues><a:Id>d9bc28a5-54a5-e311-98bb-0050569e3609</a:Id><a:LogicalName>task</a:LogicalName><a:RelatedEntities/></b:value></a:KeyValuePairOfstringanyType></InputParameters><IsExecutingOffline>false</IsExecutingOffline><IsInTransaction>true</IsInTransaction><IsOfflinePlayback>false</IsOfflinePlayback><IsolationMode>1</IsolationMode><MessageName>Create</MessageName><Mode>0</Mode><OperationCreatedOn>2014-03-06T17:27:52.9443235Z</OperationCreatedOn><OperationId>00000000-0000-0000-0000-000000000000</OperationId><OrganizationId>104395b5-b97f-485b-8dde-d5d327c23709</OrganizationId><OrganizationName>MyOrganization</OrganizationName><OutputParameters xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="idhttp://schemas.datacontract.org/2004/07/System.Collections.Generic"><a:KeyValuePairOfstringanyType><b:key>id</b:key><b:value i:type="c:guid" xmlns:c="d9bc28a5-54a5-e311-98bb-0050569e3609</OutputParameters><OwningExtension">http://schemas.microsoft.com/2003/10/Serialization/">d9bc28a5-54a5-e311-98bb-0050569e3609</b:value></a:KeyValuePairOfstringanyType></OutputParameters><OwningExtension xmlns:a="5e1ba912-45a5-e311-98bb-0050569e3609sdkmessageprocessingstepSerializePluginContext.SerializingPlugin">http://schemas.microsoft.com/xrm/2011/Contracts"><a:Id>5e1ba912-45a5-e311-98bb-0050569e3609</a:Id><a:LogicalName>sdkmessageprocessingstep</a:LogicalName><a:Name>SerializePluginContext.SerializingPlugin: Create of task</a:Name></OwningExtension><Parent><BusinessUnitId>bbc3c04d-654d-e311-9b5e-0050569e3609</BusinessUnitId><CorrelationId>044e7768-51f2-4f58-8a0c-ce6ba352d3d2</CorrelationId><Depth>1</Depth><InitiatingUserId>4a4db552-6d4d-e311-a499-0050569e3609</InitiatingUserId><InputParameters xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="Targethttp://schemas.datacontract.org/2004/07/System.Collections.Generic"><a:KeyValuePairOfstringanyType><b:key>Target</b:key><b:value i:type="a:Entity"><a:Attributes><a:KeyValuePairOfstringanyType><b:key>subject</b:key><b:value i:type="c:string" xmlns:c="Where">http://www.w3.org/2001/XMLSchema">Where is the Regarding Object Id</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>scheduledend</b:key><b:value i:type="c:dateTime" xmlns:c="2014-03-11T04:00:00Zprioritycodehttp://www.w3.org/2001/XMLSchema">2014-03-11T04:00:00Z</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>prioritycode</b:key><b:value i:type="a:OptionSetValue"><a:Value>1</a:Value></b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>ownerid</b:key><b:value i:type="a:EntityReference"><a:Id>4a4db552-6d4d-e311-a499-0050569e3609</a:Id><a:LogicalName>systemuser</a:LogicalName><a:Name i:nil="true"/></b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>actualstart</b:key><b:value i:type="c:dateTime" xmlns:c="2014-03-06T17:27:52.7968176Zisbilledhttp://www.w3.org/2001/XMLSchema">2014-03-06T17:27:52.7968176Z</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>isbilled</b:key><b:value i:type="c:boolean" xmlns:c="falseisworkflowcreatedhttp://www.w3.org/2001/XMLSchema">false</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>isworkflowcreated</b:key><b:value i:type="c:boolean" xmlns:c="falseisregularactivityhttp://www.w3.org/2001/XMLSchema">false</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>isregularactivity</b:key><b:value i:type="c:boolean" xmlns:c="falseactivityidhttp://www.w3.org/2001/XMLSchema">false</b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>activityid</b:key><b:value i:type="c:guid" xmlns:c="d9bc28a5-54a5-e311-98bb-0050569e3609http://schemas.microsoft.com/2003/10/Serialization/">d9bc28a5-54a5-e311-98bb-0050569e3609</b:value></a:KeyValuePairOfstringanyType></a:Attributes><a:EntityState i:nil="true"/><a:FormattedValues/><a:Id>d9bc28a5-54a5-e311-98bb-0050569e3609</a:Id><a:LogicalName>task</a:LogicalName><a:RelatedEntities/></b:value></a:KeyValuePairOfstringanyType><a:KeyValuePairOfstringanyType><b:key>SuppressDuplicateDetection</b:key><b:value i:type="c:boolean" xmlns:c="true</InputParameters><IsExecutingOffline>false</IsExecutingOffline><IsInTransaction>true</IsInTransaction><IsOfflinePlayback>false</IsOfflinePlayback><IsolationMode>1</IsolationMode><MessageName>Create</MessageName><Mode>0</Mode><OperationCreatedOn>2014-03-06T17:27:52.8343191Z</OperationCreatedOn><OperationId>00000000-0000-0000-0000-000000000000</OperationId><OrganizationId>104395b5-b97f-485b-8dde-d5d327c23709</OrganizationId><OrganizationName>MyDEV</OrganizationName><OutputParameters">http://www.w3.org/2001/XMLSchema">true</b:value></a:KeyValuePairOfstringanyType></InputParameters><IsExecutingOffline>false</IsExecutingOffline><IsInTransaction>true</IsInTransaction><IsOfflinePlayback>false</IsOfflinePlayback><IsolationMode>1</IsolationMode><MessageName>Create</MessageName><Mode>0</Mode><OperationCreatedOn>2014-03-06T17:27:52.8343191Z</OperationCreatedOn><OperationId>00000000-0000-0000-0000-000000000000</OperationId><OrganizationId>104395b5-b97f-485b-8dde-d5d327c23709</OrganizationId><OrganizationName>MyDEV</OrganizationName><OutputParameters xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="<OwningExtension">http://schemas.datacontract.org/2004/07/System.Collections.Generic"/><OwningExtension xmlns:a="5bcabb1b-ea3e-db11-86a7-000a3a5473e8sdkmessageprocessingstepObjectModel">http://schemas.microsoft.com/xrm/2011/Contracts"><a:Id>5bcabb1b-ea3e-db11-86a7-000a3a5473e8</a:Id><a:LogicalName>sdkmessageprocessingstep</a:LogicalName><a:Name>ObjectModel Implementation</a:Name></OwningExtension><Parent i:nil="true"/><PostEntityImages xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="<PreEntityImages">http://schemas.datacontract.org/2004/07/System.Collections.Generic"/><PreEntityImages xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="<PrimaryEntityId>d9bc28a5-54a5-e311-98bb-0050569e3609</PrimaryEntityId><PrimaryEntityName>task</PrimaryEntityName><SecondaryEntityName>none</SecondaryEntityName><SharedVariables">http://schemas.datacontract.org/2004/07/System.Collections.Generic"/><PrimaryEntityId>d9bc28a5-54a5-e311-98bb-0050569e3609</PrimaryEntityId><PrimaryEntityName>task</PrimaryEntityName><SecondaryEntityName>none</SecondaryEntityName><SharedVariables xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="DefaultsAddedFlaghttp://schemas.datacontract.org/2004/07/System.Collections.Generic"><a:KeyValuePairOfstringanyType><b:key>DefaultsAddedFlag</b:key><b:value i:type="c:boolean" xmlns:c="true</SharedVariables><Stage>30</Stage><UserId>4a4db552-6d4d-e311-a499-0050569e3609</UserId></Parent><PostEntityImages">http://www.w3.org/2001/XMLSchema">true</b:value></a:KeyValuePairOfstringanyType></SharedVariables><Stage>30</Stage><UserId>4a4db552-6d4d-e311-a499-0050569e3609</UserId></Parent><PostEntityImages xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="<PreEntityImages">http://schemas.datacontract.org/2004/07/System.Collections.Generic"/><PreEntityImages xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="<PrimaryEntityId>d9bc28a5-54a5-e311-98bb-0050569e3609</PrimaryEntityId><PrimaryEntityName>task</PrimaryEntityName><SecondaryEntityName>none</SecondaryEntityName><SharedVariables">http://schemas.datacontract.org/2004/07/System.Collections.Generic"/><PrimaryEntityId>d9bc28a5-54a5-e311-98bb-0050569e3609</PrimaryEntityId><PrimaryEntityName>task</PrimaryEntityName><SecondaryEntityName>none</SecondaryEntityName><SharedVariables xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="DefaultsAddedFlaghttp://schemas.datacontract.org/2004/07/System.Collections.Generic"><a:KeyValuePairOfstringanyType><b:key>DefaultsAddedFlag</b:key><b:value i:type="c:boolean" xmlns:c="true</SharedVariables><Stage>40</Stage><UserId>4a4db552-6d4d-e311-a499-0050569e3609</UserId></MyPluginContext">http://www.w3.org/2001/XMLSchema">true</b:value></a:KeyValuePairOfstringanyType></SharedVariables><Stage>40</Stage><UserId>4a4db552-6d4d-e311-a499-0050569e3609</UserId></MyPluginContext>- Edited by SPCRM2011 Thursday, March 6, 2014 7:48 PM
Thursday, March 6, 2014 7:46 PM -
Hi,
Looks like when we try to create a Phone call thru Social pane, the plugin context does not contain RegardingObjectId.
In this case,
1. you will have to modify your PostCreate plugin code to first retrieve the RegardingObjectId from the DB using the phonecall entity guid (just created) in the context.
OR
2. you will have to set up a PostEntityImage (with regardingobjectid attribute) in the Plugin registration and access it to find the value of regardingobjectid
If you add this logic it will work in both Social Pane as well as from Activities.
Thanks,
Swaroop
- Edited by Swaroop_d Thursday, March 6, 2014 9:11 PM
Thursday, March 6, 2014 9:10 PM -
The suggestion in the previous post may work, but it depends how CRM is sending the data.
It may be that CRM sends the data as a create (without the regardingobjectid), followed by an update (that sets the regardingobjectid). Try registering your plugin on the update message as well, to see if this is the case
Alternatively, it may be that CRM is treating the regardingobjectid as an activityparty, and it may not be available within the transaction stages of the plugin pipeline. I'd try registering the plugin to run asynchronously (which will beoutside the transaction) to see if receives the regardingobjectid
Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk
Thursday, March 6, 2014 9:37 PMModerator -
There is no regardingobjectid either on the PostImage so not sure how Microsoft is passing the regardingobjectid from the social pane. Anyhow I am just going to retrieve the task or phone call check if the regardingobjectid is populated and then go update the AccountId.
I really do not understand why Microsoft does things differently in different areas. I have spent hours trying to figure this out.
Thanks everyone for you input.
Friday, March 7, 2014 2:36 PM -
There is no regardingobjectid either on the PostImage so not sure how Microsoft is passing the regardingobjectid from the social pane. Anyhow I am just going to retrieve the task or phone call check if the regardingobjectid is populated and then go update the AccountId.
I really do not understand why Microsoft does things differently in different areas. I have spent hours trying to figure this out.
Thanks everyone for you input.
Hi,
I am facing the same problem, and wondering if there has been any fix from Microsoft to address this?
Alternatively, how did you handle this? We did try using the PostImages and also retrieving the data from DB but neither of these contain the RegardingObjectID. Please advise.
Regards,
Yogesh
Tuesday, November 11, 2014 9:36 AM -
I was facing the same issue. I have done some research in CRM 2016, and found out that, When the activity will be created that time the regarding field will not be updated. it will be null. so we don't get that attribute in target entity.
-----------------------------------
the solution i found is register the same plugin on post update of the task of any activity. that time you will get the regardingobjectid.
----------------------------------------------------------------------------------
To find this i enabled the audit on the task entity and also on the regarding field of the task entity.
Thursday, May 19, 2016 3:16 PM