Filtering Entities with type Entity Reference?

前端 未结 3 851
旧时难觅i
旧时难觅i 2021-01-26 11:30

How do I query using the string value for an entity reference object?

QueryExpression query = new QueryExpression(\"entityName\");
query.Criteria = new FilterExp         


        
3条回答
  •  轮回少年
    2021-01-26 11:41

    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:

    1. Retrieve all the GUID's, convert them to a list of strings, and find your subset by querying that list (i.e. with LINQ).
    2. Write a very simple onCreate plugin or workflow that sets a new text field on the entity to the GUID. Then you have the GUID as a string, to work with as you please.

    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 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:

    
        
            
            
            
                
            
        
    
    

提交回复
热议问题