locked
How can I get regardingobjectid of task? RRS feed

  • Question

  • In my case,  incident is the parent entity. I am firing plugin on status update of task and I have tried :

    if (context.InputParameters.Contains("EntityMoniker") && context.InputParameters["EntityMoniker"] is EntityReference

    )

    {

     EntityReference RegId = (EntityReference)entity.Attributes["regardingobjectid"];

     

    }

     

     

    Pl help .

     

     I am getting null in RegId. I am registering my plugin on setstate and setstatedynamicentity both.



    Friday, July 22, 2011 6:52 AM

Answers

  • Hi,

    Just saw another problem in your code that you are not getting task entity reference from context paramters, the complete code will be:

    // Check if SetState message is triggered on task activity
    if (context.InputParameters.Contains("EntityMoniker")
    && context.InputParameters["EntityMoniker"] is EntityReference
    && ((EntityReference)context.InputParameters["EntityMoniker"]).LogicalName == "task")
    {
    	switch (context.MessageName)
    	{
    		case "SetStateDynamicEntity":
    		
    		EntityReference taskEntityRef = (EntityReference)context.InputParameters["EntityMoniker"];
    
    		entity taskEntity = service.retrieve(taskEntityRef.LogicalName, taskEntityRef.Id, new ColumnSet(new string[]{"regardingobjectid"}));
    
    		EntityReference RegardingObjectId = (EntityReference)taskEntity.Attributes["regardingobjectid"]; 
    		
    
    		break;
    	}
    }
    
    


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Jehanzeb.Javeed Saturday, July 23, 2011 6:23 AM
    • Marked as answer by Priya D Monday, July 25, 2011 6:33 AM
    Saturday, July 23, 2011 6:23 AM

All replies

  • How are you populating the 'entity' variable ? If you do an explicit retrieve to retrieve the task, and ensure that regardingobjectid is in the column set, then the regaridngobjectid will be available (assuming that a value is set for it).

    Alternatively, It may be possible to register an image against the plugin step - if so you could get the data from the image (via context.PreEntityImages or PostEntityImages), but I'm not sure if that works on the SetState messages


    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Friday, July 22, 2011 12:00 PM
    Moderator
  • Hi David,

     

    Thanks for your reply. Wanted to tell u I have tried Image but that didnt work either. 

     

    Saturday, July 23, 2011 4:19 AM
  • Hi,

    In SetStateDynamicEntity message (SetState will not trigger only SetStateDynamicEntity will trigger on status change of task entity) you will only recieve the EntityRefrence and Status, to get the regardingobjectid you might need to the entity data via service.retrieve method i.e.

     

    entity taskEntity = service.retrieve(RegId.LogicalName, RegId.Id, new ColumnSet(new string[]{"regardingobjectid"}));
    
    EntityReference RegardingObjectId = (EntityReference)taskEntity.Attributes["regardingobjectid"]; 
    

     

     


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".


    Saturday, July 23, 2011 6:18 AM
  • Hi,

    Just saw another problem in your code that you are not getting task entity reference from context paramters, the complete code will be:

    // Check if SetState message is triggered on task activity
    if (context.InputParameters.Contains("EntityMoniker")
    && context.InputParameters["EntityMoniker"] is EntityReference
    && ((EntityReference)context.InputParameters["EntityMoniker"]).LogicalName == "task")
    {
    	switch (context.MessageName)
    	{
    		case "SetStateDynamicEntity":
    		
    		EntityReference taskEntityRef = (EntityReference)context.InputParameters["EntityMoniker"];
    
    		entity taskEntity = service.retrieve(taskEntityRef.LogicalName, taskEntityRef.Id, new ColumnSet(new string[]{"regardingobjectid"}));
    
    		EntityReference RegardingObjectId = (EntityReference)taskEntity.Attributes["regardingobjectid"]; 
    		
    
    		break;
    	}
    }
    
    


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Jehanzeb.Javeed Saturday, July 23, 2011 6:23 AM
    • Marked as answer by Priya D Monday, July 25, 2011 6:33 AM
    Saturday, July 23, 2011 6:23 AM
  • Hi, Jehanzeb.Javeed,

    Thanks. Its working .

     

    Monday, July 25, 2011 10:26 AM