How do I query using the string value for an entity reference object?
QueryExpression query = new QueryExpression(\"entityName\");
query.Criteria = new FilterExp
While it appears that we're out of luck on getting the "like" operator to compare a string to a GUID on the fly, there are at least a couple potential workarounds:
Here's code I use in a workflow that does exactly what I'm describing (i.e. populates the GUID into a text field). It sets an output parameter to the GUID, then the next step of the workflow populates that value into the field.
public partial class GetGuid : BaseWorkflow
{
[Output("Entity Id")]
public OutArgument<string> EntityId { get; set; }
protected override void ExecuteInternal(LocalWorkflowContext context)
{
EntityId.Set(context.CodeActivityContext, context.WorkflowContext.PrimaryEntityId.ToString());
}
}
Please also note that while the "like" operator doesn't work for GUID's, "greater than" and "less than" do, so something like this works:
<fetch>
<entity name="account" >
<attribute name="accountid" />
<attribute name="name" />
<filter type="and" >
<condition attribute="accountid" operator="gt" value="14000000-0000-0000-0000-000000000000" />
</filter>
</entity>
</fetch>
parentaccountid is a Lookup Property .
LinkEnitity can only be applied for another entities.
The easy way for filtering is adding name at the end of attribute.
query.Criteria.AddCondition("parentaccountidname", ConditionOperator.Like, "%In%");
Thanks to Dave, refer here for Q&A
You need to filter on the name
attribute of the associated account
entity.
Join the account
entity to the opportunity
entity and apply a ConditionExpression
to it like this:
var query = new QueryExpression("opportunity");
LinkEntity link = query.AddLink("account", "parentaccountid", "accountid");
link.AddCondition("name", ConditionOperator.BeginsWith, "14");