UniversalViewerWithCustomQuery Where Clause using a QueryString Param

Tyler Penney asked on July 6, 2018 23:18

I would like to load a page with the UniversalViewerWithCustomQuery webpart using a query string parameter in the page URL:

Page URL w/ Query string parameter: mysite\home\mypage.aspx?id=3

My Content Queries that I have tried thus far:
SELECT Top 1 ObjectID,Field1,Field2 FROM MyTable Where ObjectID = {% QueryString.id %} Get Error: Incorrect syntax near '%'. So then I tried: SELECT Top 1 ObjectID,Field1,Field2 FROM MyTable Where ##WHERE## Content filter Where clause: ObjectID = {% QueryString.id %} Get Error: Invalid SQL query in property "wherecondition".

I have also tried to use just a string {% '3' %} in place of the querystring parameter and get the same errors. I know I'm doing something wrong but cannot figure out what...

Recent Answers


Brenden Kehren answered on July 7, 2018 00:29 (last edited on December 10, 2019 02:31)

When you're entering the macro are you using the arrow to the left of the input box to enter it? Your condition should look like this:

ObjectId = {% QueryString.GetValue("id", 0) |(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on July 7, 2018 00:48 (last edited on December 10, 2019 02:31)

the id is not passed to the page as a query string parameter. you should put something like this in your Where text box: {%string.IsNullOrEmpty(QueryString.id)?"":"objectid="+ QueryString.id|(identity)GlobalAdministrator%}. Secondly make sure that ObjectID exists in MyTable.

P.S. If you are doing this on different objects(tables), your query is bunch of unions, but cms adds your condition each query, i.e

SELECT *
FROM (
(
SELECT null as [ObjectID], ...
FROM View_CMS_Tree_Joined AS V WITH (NOLOCK, NOEXPAND) INNER JOIN MyTable1 
WHERE (objectid=1)...
)
UNION ALL
(
SELECT ObjectID as [ObjectID], ...
FROM View_CMS_Tree_Joined AS V WITH (NOLOCK, NOEXPAND) INNER JOIN MyTable2 
WHERE (objectid=1)...

That might crush as well

0 votesVote for this answer Mark as a Correct answer

vasu yerramsetti answered on July 7, 2018 13:02 (last edited on December 10, 2019 02:31)

Hi Tyler,

Try with below Query syntax :

SELECT ##TOPN## ##COLUMNS## FROM MyTable Where ##WHERE##

Input parameters from web part

  1. Select top N: 1
  2. WHERE condition: ObjectID={% QueryString.GetValue("id", 0)|(identity)GlobalAdministrator%} [Or {%id%}]
  3. Columns: ObjectID,Field1,Field2
0 votesVote for this answer Mark as a Correct answer

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