How custom queries work on OWL
Hi, everyone.
This is kind of Part 2 to the previous document How Queries and DefaultSets work on OWL .
Whenever we create a custom BO, a standard query “QueryByElements” is automatically created.If the BO has some nodes, standard quries for those nodes are also created by the studio.Here are the limitations of thoes standard queries.
1. They never include SearchText properties.
2. They can only search for only one level. The root-level query can only be used for root-level elements , not for node-level elements and vice versa.
Custom queries can resolve them.
1. How to create a custom query
We need a BO.Here is the definition of the sample BO that I am going to use along this doc.
businessobject SalesOrder {
element SalesOrderID :LANGUAGEINDEPENDENT_MEDIUM_Text;
node Item[1,n]{
element ItemID :LANGUAGEINDEPENDENT_MEDIUM_Text;
element ItemName :LANGUAGEINDEPENDENT_MEDIUM_Text;
}
}
1.1 Root-level custom query
Right click the BO and select Create Query. The Query Wizard will open.
Step one: Selecting BO and Node.
Root is selected as Parent Node.
Query Node Name is changed to RootLevel . (Any name you want ).
Step two : Select Query Fields.
Only those fields selected here can be used for “Selection” , “Basic Find” and “Result”.(explained at next step).
Step three: Define Query Parameters
You don’t have to check every checkbox.
Selection : These are the search parameters. These fields can be used to query the BO in ABSL and can be used as “Query Parameter Binding” for Query on OWL. Only the fields that are checked as Selection in “Define Query Parameter” step can be added to Selected Query Parameters and used in DefaultSets.
Basic Find : These fields are included in SearchText field. After activating the query(you can’t really activate the query,you have to activate the BO instead), there will be a SearchText field if you checked at least one field in Basic Find column.
Result : This is what you can get from the query. Please note that only root elements can be checked here becuase it is a root level query.(More detail in the try out below)
1.3 RootLevel query try out!
To understand these three things , let’s do a try out.
Activate the BO and check in the query. Then open the OWL. You will see the new Query “RootLevel” in the Queries.
( If you can’t see the new “RootLevel” query, just click Update Metadata button on the tool bar.)
We are going to bind the datalist with our new Query.
Open the datamodel tap. Unbind the datalist. Bind the datalist with our new Query (The data list name is changed to RootLevel) . Bind the SalesOrderID of DataList to SalesOrderID of RootLevel Query. ( You can bind SalesOrderID from RootLevel Query here because you checked the check box in the Result column in the step three: Define Query Parameter.Only that field can be used to bind here. NodeID is produced by the system.)
Bind the RootLevel Query with the Query of the datalist RootLevel.
Originally, the Query is bind with QueryByElements of SalesOrder and Result List is assigned to /Root/RootLevel (that is bound with our new “RootLevel” query in datamodel in step 2.) <sorry for the confusing names> .This will definitely give a backend error if activeated and run.
Query and Datalist must be bound to the Same Query of a BOModel.
Unbind the query. And bind the query with our new RootLevel query.
And add any query elements to Selected Query Parameters and bind with fields from datamodel (you have to pre-create new fields to be able to bind with the parameters, the names will be automatically changed after binding.) so that you can use these query parameters in later processes (like in the datasets or in the advanced search)
Advanced Search
Click Advanced at the left cornor.
Just drag and drop the fields that you want to search for from BO Data Model. (Fields bound with Selected Query Parameters at above step , step 3) . Don’t add the search text. We are going to use the search text in Go search box.
For the searchtext , select Selection Group and click … of Search Textbinding.
And bind with SearchText from DataModel.
Let’s test it.
Before testing , please bare in mind these things.
1. (* Datalist from datamodel and Query from control must be bound to the Same Query you created)
2. Execute the query in the studio to check if it is working or not. This is important. Sometimes, the query is not working properly. You have to reactivate the BO again.
Ok , let’s test.
I have 2 sales order here. The Item cannot be show anymore because we didn’t bind the Item datalist for we don’t have Item fields in our RootLevel Query. We can only check SalesOrderID field in Result column. 🙁 (In Step Three : Define Query Parameters)
Update: The problem of not being able to show Item elements is solved here.How to show Items (Nodes) using a Root-Level Query
But we can search for all the elements because we checked every element in Basic Find column (In Step Three:Define Query Parameters) .Below, I searched by ItemID item2. Only “SO1” has item “item2”. So , it only shows up.
And you can also search by fields in Advanced Search Pane. Here is an example.
1.2. Node-level custom query
This document is pretty long. Please try it out yourself for Node-Level cutom query. 🙂 .
Good Luck! ! ! .
Thanks for reading.
Freds.
There is an alternative way to avoid creating custom queries for this kind of requirements.
That is using SADL queries.
Please refer to this document Basics of SADL Query written by Fernando Giroleti
Thanks for sharing the knowledge Fred 🙂 Really appreciate it .
Hi Fred K,
Nice document Thanks for sharing..................
Regards,
Mithun
Excellent Fred!
This is an important topic to understand and not easy at all to manage without this kind of hints!
Thank you very much.
Best regards.
Jacques-Antoine
Hi Fred,
thank you for this nice document. ➕
I have only one small remark, maybe its only a beginner problem, but I followed all you steps but still get an error message every time when trying in the Browser.
I found the solution:
I have some Event handler implemented like RefreshListHandler.
After Step 1.3 where you bind the Data List to RootLevel, the TargetList in the Event Handler is deleted.
You have to rebind the Event Handler.
I didn't do that at first and wondered why I get an Error 😕
Best regards,
Astrid 🙂
Hi Fred,
I am trying to create a query as in Title 1.1, but I get an error : Checked failed
I would like to hear the recommendation.
Regards,
Abdulkadir