Hi Guys, I am creating a plugin, where i just need to assign a task to a team, the plugin tiggers an error and it is registered in the post event and a Create message name to a custom entity. I have debugged it and it gives this error - "error in assigning task : System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Creating Entity with an invalid parent. Entity: Task, ReferencingAttribute:regardingobjectid (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault)."
Anyone knows why?
My code is below:
if(context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity travelDetail = (Entity)context.InputParameters["Target"];
if(travelDetail.LogicalName != "gg_traveldetail") { return; }
try
{
QueryByAttribute teamQuery = new QueryByAttribute("team");
teamQuery.AddAttributeValue("name", "Travel Consultants");
EntityCollection retrievedTeam = service.RetrieveMultiple(teamQuery);
Entity travelConsultantTeam = (Entity)retrievedTeam.Entities[0];
Guid travelconId = travelConsultantTeam.Id;
Entity task = new Entity("task");
task.Attributes["subject"] = "New Travel Booking Created";
task.Attributes["ownerid"] = new EntityReference(travelConsultantTeam.LogicalName, travelconId);
task.Attributes["description"] = "A new travel booking has been created for a staffing role.";
if (context.OutputParameters.Contains("id"))
{
Guid regardingobjectid = new Guid(context.OutputParameters["id"].ToString());
string regardingobjectidType = "gg_traveldetail";
task.Attributes["regardingobjectid"] =
new EntityReference(regardingobjectidType, regardingobjectid);
}
service.Create(task);
Thanks for the help guys.
*This post is locked for comments
I have the same question (0)