RE: Virtual Entity Plugin Target Is Undefined
Hello,
as Andrew has pointed out, you'll need to do some query parsing in the plugin. "Target" input parameter would work IF this plugin were for the account entity (on "Update", for example). Since it's a plugin for the "licence" entity, and it's a Retrievemultiple pluing, you'll need to parse the query and extract account id from the query conditions. I am not sure what the schema name of the account lookup attribute is on that entity, but here is more or less how that code might look like:
foreach (ConditionExpression condition in conditions)
{
if (condition.AttributeName == "<account_id_lookup_attribue_name>")
{
var accountId = condition.Values[0];
}
}
In this loop, you'll likely need to use Criteria.Filters[0].Conditions from the incoming QueryExpression. Might be Criteria.Conditions, though. Or, depending on the complexity of the view, might be something else - you'll likely need to look at the query a little closer then (I'd suggest converting to Fetch from the plugin - see below - and, then, logging it through the tracing service or just by throwing an exception with that fetch in the error message)
That code would be for the QueryExpression - if it's a virtual entity, you should probably be fine (stage 30? Should be QueryExpression there). Otherwise, if you need to do it in stage 20/40, you may need to "cast" between FetchExpression and QueryExpression (or you may need a similar code to parse FetchExpression):
https://docs.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.fetchxmltoqueryexpressionrequest?view=dynamics-general-ce-9
docs.microsoft.com/.../microsoft.crm.sdk.messages.queryexpressiontofetchxmlrequest