Reputation: 39270
I'm using late bound and as an account is created, I'm creating a phone call too. I also found a very useful example doing almost that. The only thing that bothers me is that the following lines:
if (context.OutputParameters.Contains("id"))
{
Guid id = new Guid(context.OutputParameters["id"].ToString());
String type = "account";
followup["regardingobjectid"] = new EntityReference(type, id);
}
assume that the cause of the phone call is an account. Well, it is, but in the future it might be not. I tried to get the type as follows:
if (context.OutputParameters.Contains("id"))
{
Guid id = new Guid(context.OutputParameters["id"].ToString());
String type = context.OutputParameters["logicalname"] as String;
followup["regardingobjectid"] = new EntityReference(type, id);
}
but then I got error telling me that such a field doesn't exist. Is the field name wrong? Or am I using all the wrong approach to retrieve the logical name of the entity (i.e. the actual name of the entity type, be that account, contacts or a crazydonkeyass)?
Also, I'm not entirely sure if OutputParameters is the right place to look in. Suggestions?
Upvotes: 1
Views: 2858
Reputation: 2087
This is available in context.PrimaryEntityName
EDIT
Here's the bit from the example that checks if this is account
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters["Target"];
// Verify that the target entity represents an account.
// If not, this plug-in was not registered correctly.
if (entity.LogicalName != "account")
return;
I guess that's why they have account hardcoded (ugly!)
Upvotes: 1