Here you can find the documentation about creating a CS element :
Creating Query Assets :
quote : When the asset is rendered, it does not invoke the query directly. Either the template element that formats the asset or a template element that formats the query is coded to invoke a standard WebCenter Sites element called:
This element runs the query asset when the asset it is associated with is rendered, which means the resultset is dynamic.
for examples on the templates please see :
for more info on specific tags see the tag reference :
JSP Full TOC
Thanks Pietro for your reply .
I have gone through these sections before and what i want to know is
In the above link go to section 26.2.2 , which says we can create query assets directly or indirectly. So, what i want to know is the indirect method of creating query assets .
The section says "You can write the query in an element and then store the location of that element in the query asset by identifying it in the Element name field in the Query form."
Can you please explain me in detail, the above line ?
that's the reason why i linked the JSP alphabetic order for tags , see tags like : ics:sql ics:callsql
once you have the element with the sql logic then you can select it int he query asset creation form , last box at the bottom allows you to select an existing element , query type --> Elelemt --> element name
This is what i tried just to test the working of it
1) Created a CSElement named "CallQuery" which holds a simple query with the below contents in it.
<%String sqlQuery = "Select name from Query"; %>
<ics:sql listname="queryList" sql="<%=sqlQuery %>" table="Query"/>
<ics:listget fieldname="name" listname="queryList"/><br/>
2) Create a query asset "TestQuery" using the above element name i,e., In element option i entered "CallElement"
3) Created a pulldown attribute editor with queryassetname call to "TestQuery" and associated it to an attribute of type string(multiple).
4) When i tried to create an asset which is holding this attribute ,i didn't get any contents in the dropdown.
When i use the same code present in the cselement and use it in a template to verify the results ,i am getting 10-15 results.
Am i missing something or am i doing anything wrong ? Please let me know if you need any more details.
Thanks and Regards,
I tried with "select name as value from Query" and it gave me "null" when previewed in a template. But even after getting null i gave it a try in CS Element but didn't get expected results so I ruled it out.
Coming to second option that you mentioned "put the query in cs element without ics tag" , shall i try the below code ? or is it something else ?
Select name from Query
For the PULLDOWN attribute editor using a Query asset, you need the following:
- The SQL in the query asset must return a "value" column. For example:
select name as value from shippingtype
- If the data type of the attribute using the attribute editor is "asset", the query must also return the assets' IDs. For example:
select name as value, id as assetid from Product where...
Your original CallQuery was mostly correct except you need to
1. Return a value column (and possibly an id column)
2. Not loop over the results. The attribute editor will loop over the results.
3. Set the listname the the variable "list".
<% String sqlQuery = "select name as value from Query"; %> <ics:sql listname='<%=ics.GetVar("list")%>' sql='<%=sqlQuery%>' table="Query"/>
Note that this will return a list of names of Query assets, which may or may not be what you need.
I hope this helps.
The above solution works when the query asset that we create belongs to one particular site. But if i share this particular query asset and cs element to site1 and site2 ,how can I fetch the results dynamically based on the current site I am currently present.
I understand that we cannot use ics.getvar("site") in a CS element. Correct me if i am wrong.
You can use ics.GetSS
Var("pubid") to determine the site. (This gives you the ID of the site when the user is logged into the UI.)
I know this is strange but what I found out was when i use ics.GetList() instead of ics.GetVar() in the below tag,the previous list of results which were coming correctly will go null. Could you please tell me more about this ?
<ics:sql listname='<%=ics.GetVar("list")%>' sql='<%=sqlQuery%>' table="Query"/> -------------> Gives you valid result
<ics:sql listname='<%=ics.GetList("list")%>' sql='<%=sqlQuery%>' table="Query"/> --------------> Gives you null (Throws NullPointerException)
Ideally <ics:sql> tags listname attribute takes list as the value but here it only takes variable as its value which i found weird . Hope my question is clear.