Try our conversational search powered by Generative AI!

Finding empty attributes


I am trying to write a query to locate blogs where a specific attribute is empty but I am not sure how to construct the query. 

Any suggestions out there? 

Aug 26, 2009 10:23

Could you elaborate further on what you want to achieve?  Makes it easier to come up with an example. Thanks!


Aug 28, 2009 11:03

I'm also trying to do the same as Claus.

In my case I want to get all users that has an attribute not set to String.Empty and null.
uq["MyAttribute"] != String.Empty && uq["MyAttribute"] != null

I was trying this but it did not do what I want. 

UserQuery uq = new UserQuery();
StringCriterion strCriterion = new StringCriterion();
strCriterion.WildCardType= WildCardType.None;
strCriterion.Value = String.Empty;
uq["MyAttribute"] = strCriterion;
UserCollection users = CommunitySystem.CurrentContext.DefaultSecurity.GetQueryResult(uq);

Aug 31, 2009 13:47

Hi guys,

 Try this:

public class NonEmptyStringCriterion : StringCriterion {
public override string GetQuery(string propertyName)
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.AppendFormat("NOT ({0} {1} '{2}'", propertyName, EQUALS_OPERATOR, String.Empty);
queryBuilder.AppendFormat(" {0} {1} IS NULL)", OR_OPERATOR, propertyName);
return queryBuilder.ToString();

Instead of assigning a StringCriterion instance to the uq["MyAttribute"] property, create an instance of NonEmptyStringCriterion and assign it instead. This will find all nonempty attributes.

Sep 04, 2009 10:38
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.