repeater where condition

Rita Mikusch asked on June 22, 2017 23:58

Hi,

I have a "folder" of documents with a custom field, let's call it "CustomField". And I'm using an hierarchical viewer to display all documents where the CustomField is empty.

But for the life of me, I can't figure out/remember the correct way to do this ... I've tried many variations of the following, but they all give me an invalid column name error.

{%CurrentDocument["CustomField"] != ""%}

Thank you.

Correct Answer

Brenden Kehren answered on June 23, 2017 01:08

Get rid of the double quotes and use single.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on June 23, 2017 00:08

The statement will only check the current selected document. If you want to check a folder, then do something like:

{% Documents["/folder/path/"].Children.Where("CustomField = ''").Count %}

0 votesVote for this answer Mark as a Correct answer

Rita Mikusch answered on June 23, 2017 00:18

Hi, Thank you for the information.

The Hierarchical Viewer webpart will iterate through the documents in the current path, right? (Since I left the viewer's "Path" field blank.)

So I'd like to iterate through all the documents in the current path, and select only those whose CustomField != "".

The path can change ... so how would I refer to the documents I'm iterating through?

thank you!

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 23, 2017 00:20

Then just update your where condition to say something like:

CustomField <> ''

0 votesVote for this answer Mark as a Correct answer

Rita Mikusch answered on June 23, 2017 00:34

I'm happy to know that's SUPPOSED to work ... but it's not. Gives me this error:

Caused exception: An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.

So I tried it with a standard field ie:

MenuItemName <> ""

This gives me the same error. If I remove that WHERE condition, the error goes away. So I must be doing something else wrong.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 23, 2017 00:38

If you're selecting multiple different page types then that field will need to be added to all the page types to get around that error.

0 votesVote for this answer Mark as a Correct answer

Rita Mikusch answered on June 23, 2017 00:45

I'm only selecting one page type, and it has that field.

I'm going to delete the page type and recreate it. Maybe it's buggy. Fortunately it's a new page type and I haven't used it for anything so far except testing this hierarchical viewer.

thank you.

0 votesVote for this answer Mark as a Correct answer

Rita Mikusch answered on June 23, 2017 01:07

I've figured what the problem is .... don't know what the solution is though ...

(DocumentTypeCustomFieldName <> "test")

The above is the wrong syntax ... cause the error I'm getting now is:

Caused exception: Invalid column name 'test'

Would anybody know what the correct syntax is? This is for a WHERE condition that's going into a repeater webpart.

thank you!

0 votesVote for this answer Mark as a Correct answer

Rita Mikusch answered on June 23, 2017 01:19

Thank you, that worked!!

I just googled t-sql and string literals ... and yeah the error messages make sense now. Use single quotes for string literals, and double quotes for column names.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.