Mark Fasel
Mark Fasel

Reputation: 307

How do I use a widget parameter in a custom query (widget is based on repeater with custom query)

I am building a custom widget that is based on the kentico repeater with custom query. I am using the custom query to query my custom table and display a transformation from that table. In my widget I have a custom parameter I have set up that I would like to use in my query for the where clause to make it more user friendly. Any help would be awesome! Thanks

select ##TOPN## * 
from customtable_phone_directory
where Category = '{% DirectoryCategory %}'
order by ItemCreatedWhen asc

This does not seem to work. I even tried this:

select ##TOPN## * 
from customtable_phone_directory
where Category = ##DirectoryCategory##
order by ItemCreatedWhen asc

DirectoryCategory is the custom property I have set up in the widget.

Thanks

Upvotes: 0

Views: 241

Answers (1)

Boris P.
Boris P.

Reputation: 415

The correct syntax should be

{%FieldCodeName%}

I don't think this approach will work (I think the macros are resolved when the widget/web part is loaded, not every time you change something). You could try configuring depending fields:

https://docs.kentico.com/k10/custom-development/developing-form-controls/reference-field-editor (field advanced settings)

https://devnet.kentico.com/articles/how-to-work-with-depending-fields

Also, If I remember correctly, the macro has to be set as the default value for the given field in that widget and the field cannot be editable by the editor. Otherwise this would be a security flaw, if macros would be resolved on editor accessible fields.

Instead of having a field a secondary field pass a value into the where condition you can change the Where condition form control from a text box, e.g. to a drop down form control (name;SQL query pair).

Upvotes: 1

Related Questions