Site structure
Version 4.x > Site structure > SQL query macros in document fields View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
wdaugherty-dataspringinc - 1/15/2010 12:07:11 PM
   
SQL query macros in document fields
I have created a new document call PageCatagory the has two columns, CatagoryID and CategoryName. This document type is used in the site tree to create an N-tiered category structure for the site admins to categorize the pages in the site for custom analytics purposes. I have added a custom field attribute to the Page (menu item) document type that is a list box so the user can select what category the page belongs to. The list box needs to be populated with the items from the category structure using a SQL query based on the current site that is being edited. Using the query below how can I make the site id dynamic using a macro? I have tried the query below but it throws an exception.

SELECT CategoryID, CategoryName FROM View_custom_PageCategory_Joined
where NodeSiteID = {%CurrentSiteID%}

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 1/20/2010 8:25:08 AM
   
RE:SQL query macros in document fields
Hello,

We were communicating via e-mail so for other visitors:

There are not allowed context macros in the document type fields. You would need to type in the exact value of site ID, there is not any possibility to know the context value.

Best regards,
Helena Grulichova

User avatar
Member
Member
gatsby0121 - 4/26/2011 10:26:32 AM
   
RE:SQL query macros in document fields
Is there anyway to check the current culture in the sql selector in a document field?

I've created a listbox using a query in the document field sql query box. I'm assuming no, but it's worth a shot. Basically I only want to show the list of documents in that select box, where the culture is set to the current users culture.

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 4/27/2011 12:46:03 PM
   
RE:SQL query macros in document fields
Hello,

you cannot use the context macros on the Form tab but you could use a workaround. You can use a macro:

{@CMSPreferredCulture@}

in the SQL query for the document field.

It will evaluate the current culture code.

Best regards,
Helena Grulichova

User avatar
Member
Member
gatsby0121 - 4/29/2011 8:12:41 AM
   
RE:SQL query macros in document fields
Hi, thanks again for the tip, quick question though, what would the query look like using that macro (generic fields are ok, just trying to figure out where in the query I put that, assuming the where statement)

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 5/2/2011 6:55:44 AM
   
RE:SQL query macros in document fields
Hi,

if you select the documents, you can use it in the Where condition like:

WHERE DocumentCulture LIKE '{%Cookies["CMSPreferredCulture"]%}'

Best regards,
Helena Grulichova