locked
Retrieve all activities associated with Account RRS feed

  • Question

  • I am required to write a plugin to close all associated Activities when the Account is Deactivated. I wrote the following code to retrieve all appointments associated with the account but got this error "'Appointment' entity doesn't contain attribute with Name = 'RegardingObjectId'.". Entitiy 'Appointment' has the attribute regardingobjectid. Not sure what is missing here. Please help!

    QueryByAttribute appointments = new QueryByAttribute();
    appointments.ColumnSet = new AllColumns();
    appointments.EntityName = "appointment";
    appointments.Attributes = new string[] { "regardingobjectid", "statuscode" };
    appointments.Values = new object[] { accountid, 1 };
    BusinessEntityCollection appts = service.RetrieveMultiple(appointments);

    //Close every Appointment
    foreach (BusinessEntity b_entity in appts.BusinessEntities)
     {

    //code to close activities goes here
     }

    Monday, January 10, 2011 8:47 PM

Answers

  • Very odd.  I just tried your code verbatim (although I changed the status to 3 for Completed), against an account that I know has appointments attached and it worked as expected.
    --pogo (pat)
    Monday, January 10, 2011 11:00 PM

All replies

  • Hi

    appointments.Values = new object[] { accountid, 1 };

    is invalid, accountid needs to be a guid
    Kids don't try this at home!
    Monday, January 10, 2011 10:21 PM
  • Sorry for not posting that code. accountid that I used is a variable, which is of type GUID.

    Key

     

    accountkey = (Key)entityimage["accountid"];

     

    Guid accountid = accountkey.Value;

    Monday, January 10, 2011 10:23 PM
  • Very odd.  I just tried your code verbatim (although I changed the status to 3 for Completed), against an account that I know has appointments attached and it worked as expected.
    --pogo (pat)
    Monday, January 10, 2011 11:00 PM