locked
missing letter "from" attribute RRS feed

  • Question

  • Hi All,

    Another newbie question. I am creating a plugin that fires on create of a letter. It is supposed to read the "from" attribute of the letter. My problem is that when I get the entity, the "from" and "to" fields are always empty. I have tried creating a postImage and doing a retrieve on the created entity but nether contains the "from" data. I have looked on the form customization, and it is correctly pointing at the from attribute :-(

     

    Any help appreciated :)

    Chris


    Chris
    Monday, June 20, 2011 2:02 PM

Answers

  • For debugging please try this code:

     

    public void Execute(IServiceProvider serviceProvider)

    {

    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

     

    if (context.InputParameters.Contains("Target") &&

                            context.InputParameters["Target"] is Entity)

    {

    Entity eLettert = (Entity)context.InputParameters["Target"];

    throw new InvalidPluginExecutionException((EntityCollection)eLettert["from"]).Entities.Count.ToString());

    }

    else

    throw new InvalidPluginExecutionException("Error");

    }

    • Marked as answer by ChrisAdams Tuesday, June 21, 2011 6:14 PM
    Tuesday, June 21, 2011 2:09 PM

All replies

  • "From" is a party list. So an entity collection.

     

    Use something like

    EntityCollection Parties = (EntityCollection)LetterEntity["from"];

    Monday, June 20, 2011 2:46 PM
  • Hi Jan,

    This is what I am doing, but it always returns an empty set :-(


    Chris
    Monday, June 20, 2011 3:07 PM
  • Monday, June 20, 2011 3:18 PM
    Moderator
  • Hi Jamie,

    essentially it is this

     

     

                _context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

                _tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

                _service = serviceFactory.CreateOrganizationService(_context.UserId);

    //Letter is an earlybound type from CrmSvcUtil, but it is exactly the same if I use entity.attributes["from"]

       Letter letter =  _context.PostEntityImages[_contactEntity].ToEntity<Letter>();

    //Using retrieve as below doesn't work either

       //Letter letter =  _service.Retrieve(Letter.EntityLogicalName, _context.PrimaryEntityId, new ColumnSet(true)).ToEntity<Letter>();

     

    //basically I want to run the update method on the contact if the letter is from them..

                if (letter != null &&

                    letter.RegardingObjectId.LogicalName == Contact.EntityLogicalName &&

                    letter.From.Any(f => f.ActivityPartyId == letter.RegardingObjectId.Id))

                {

                    Contact contact = _service.Retrieve(Contact.EntityLogicalName, letter.RegardingObjectId.Id, new ColumnSet(true)).ToEntity<Contact>();

                    Update(contact, DateTime.Today); //method not included here

                }

     

    Cheers


    Chris
    Monday, June 20, 2011 3:39 PM
  • Apologies, forgot to mention that _contactEntity is the name of a post image I have defined in PluginRegistration, which includes the from field.

    :-)


    Chris
    Monday, June 20, 2011 3:43 PM
  • For debugging please try this code:

     

    public void Execute(IServiceProvider serviceProvider)

    {

    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

     

    if (context.InputParameters.Contains("Target") &&

                            context.InputParameters["Target"] is Entity)

    {

    Entity eLettert = (Entity)context.InputParameters["Target"];

    throw new InvalidPluginExecutionException((EntityCollection)eLettert["from"]).Entities.Count.ToString());

    }

    else

    throw new InvalidPluginExecutionException("Error");

    }

    • Marked as answer by ChrisAdams Tuesday, June 21, 2011 6:14 PM
    Tuesday, June 21, 2011 2:09 PM
  • Hi Jan,

     

    I had switched to the InputParameters["Target"] just before you replied, and it worked :-) The problem was that the early bound property produced by CrmSvcUtil didn't work correctly.

     

    Cheers

    Tuesday, June 21, 2011 6:17 PM