on 03-28-2009 5:04 PM
Hi Friends,
I have problems using the addConditions(condString) on my query, can anyone give me an example please.
Best Regards,
David Faustini
HI,
Check My Blog
http://www.sdn.sap.com/irj/scn/weblogs?blog=/cs/junior/view/wlg/16797
Regards,
Muhammed Nishad
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
1) Create a query
For eg.: TestQuery
2) Add an attribute of the type of the node you want to put condition on.
For Eg. if ur model contains fields as Status on which u want to check, then you can have the attribute of type status and give it a name say Test_Attr
3) Give the input model class as teh TestQuery
4) Give the output query class as ur model class
5) In Add Conditions give it as
<Model Class>.STATUS =:Test_Attr
6) To set the value of TesT_Attr. set it in the supplyfunction for the query
SQ.getQueryInput().setTest_Attr("Completed");
where SQ is the instance of the query created in component controller.
I hope this will work ot for you.
Regards,
Sumit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sumit,
My problem is that i need to add conditions to query dynamically, for that I need to use the method addConditions
Look at the code below:
-
public void fireQueryHeaders( ) {
//@@begin fireQueryHeaders()
ServiceOrderModel model = ServiceOrderModel.getInstance();
QueryHeaders qHeaders = model.createQueryHeaders();
if(customer == true)
{
qHeaders.getQueryInput().setORDER_ID("45654"); // A real order number
qHeaders.addConditions("ORDERHEADER_ORDERHEADER.ORDER_ID =:ORDER_ID"); //line that turn the java exception or error
}
try
{
qHeaders.execute();
}catch (CMIException e) {
e.printStackTrace();
}
wdContext.nodeQueryResult().invalidate();
//@@end
}
-
Any idea??
Best Regards,
David Faustini
Hi David,
Sorry for a delayed reply.
Whenever we write a query there is a corresponding java editor for it which you can open by rght clicking the query editor. there you will find a querystring with where clause and all conditions taht you have given in query generator. Copy the same string along with adding the And clause to it as per your requirements in the addconditions method.
I feel this should work out for you.
Please let me know if it helps.
Regards,
Sumit
Hi Sumit,
Don't worry for the delay.
The problem persist, if I check the generated Java query on the editor the method mdGetQuery() look like this:
-
private com.sap.tc.mobile.cfs.wdbll.MobileQuery mdGetQuery() {
if ($mdQuery == null)
{
$mdQuery = new com.sap.tc.mobile.cfs.wdbll.GenericMobileQuery(
" IMPORT [ com.cts.test.model ] PARAMETER QueryHeaders BIDIRECTIONAL SELECT REFERENCE ORDERHEADER_ORDERHEADER WHERE [[ ORDERHEADER_ORDERHEADER.ORDER_ID =:ORDER_ID ]]",
associatedModel(),
associatedModelClassInfo(),
associatedModel().associatedModelInfo().
getModelClassInfo("com.cts.test.model.ORDERHEADER_ORDERHEADER"));// TODO: correct this
}
return $mdQuery;
}
-
When I try to add parameters to the query on the fire method the result is:
-
public void fireQueryHeaders( ) {
//@@begin fireQueryHeaders()
qHeaders.getQueryInput().addConditions(" [[ ORDERHEADER_ORDERHEADER.ORDER_ID =:ORDER_ID ]]");
try
{ // A real order number
qHeaders.execute();
//qHeaders.execute();
}catch (CMIException e) {
e.printStackTrace();
}
wdContext.nodeQueryResult().invalidate();
//@@end
}
-
When I call the method the exception was:
Caused by: java.lang.IllegalArgumentException: Unknown class name: ORDERHEADER_ORDERHEADER
if I comment the line:
qHeaders.getQueryInput().addConditions(" [[ ORDERHEADER_ORDERHEADER.ORDER_ID =:ORDER_ID ]]");
The query works fine but without conditions.
Regards,
David Faustini
Edited by: David Faustini on Apr 7, 2009 2:27 PM
Edited by: David Faustini on Apr 7, 2009 2:27 PM
Edited by: David Faustini on Apr 7, 2009 2:30 PM
Hi David,
Please can you put in some light on your scenario.
As per my understanding addcondition works as a concatenation of inputs.
For eg: if suppose you query for STATUS value as "finished" this is is primary input. and u will have to concatenate your next condition after the WHERE clause in the same query
SQ.addConditions("IMPORT [ com.minward ] PARAMETER Minward_Query BIDIRECTIONAL SELECT REFERENCE MATERIAL_INWARD_DO_E_TRANS_DETAIL WHERE [ MATERIAL_INWARD_DO_E_TRANS_DETAIL.STATUS = :TEST_1 ] *AND ........");*
And try running like this.. It may work out
If you running a scenario wherein the first query should return a resultset and you want to display details for returned resultsets then pass the attribute from resultset as the input to the next query.
Hi Sumit,
I Want to execute dynamic queryes. In my case my webdynpro for laptop application works for 2 roles (admini, and tecnitian). The admin need to see al orders so that in this case the query has no parameters, but if the role is tecnitian I need to show just the orders that belong to the user ORDER.USER = logged user.
My problem is that I need to add a parameter ORDERHEADER_ORDERHEADER.USER =:USER just in the cases where the user logged on the app is a tecnitian.
The query was created with USER parameter on the attribute tab and on the query tab conditions empty
So I have to scenarios:
1-User is an administrator
fire the query without conditions.
2-User is not an administrator
fire the query with ORDERHEADER_ORDERHEADER.USER =:USER condition
Can I send you the project to some address?
Regards,
David Faustini
Hi David,
As per my understanding in your scenario, you can have 2 approaches,
1) Check for admin and technician in a separate query. If it returns true for a admin, define a second query to fetch all records. If it returns false define a third query which will have the conditions for user specific records.This will be least complicated as there are no dependencies, just you need to set the inputs right for the query.
2) the addconditions method as per my understanding will not take anotehr input as you are trying to set it this way:
qHeaders.getQueryInput().addConditions(" [ ORDERHEADER_ORDERHEADER.ORDER_ID =:ORDER_ID ]");
I feel it should go like this as per the syntax:
qHeaders.addConditions("" IMPORT http:// com.cts.test.model PARAMETER QueryHeaders BIDIRECTIONAL SELECT REFERENCE ORDERHEADER_ORDERHEADER WHERE [ ORDERHEADER_ORDERHEADER.ORDER_ID =:ORDER_ID ] AND <The condition you want to add.>")
I might be wrong in the second case but by seeing the syntax as given it shoud work this way.
The first method should work better for you.
Regards,
Sumit
Edited by: Sumit Harwani on Apr 8, 2009 8:45 AM
Hi Sumit,
It doesn't work. I need to flush all my query result under the same node so the option that you suggest creating two querys doesn't apply for me. In the other case when you suggest :
qHeaders.addConditions("" IMPORT http:// com.cts.test.model PARAMETER QueryHeaders BIDIRECTIONAL SELECT REFERENCE ORDERHEADER_ORDERHEADER WHERE ORDERHEADER_ORDERHEADER.ORDER_ID =:ORDER_ID AND <The condition you want to add.>") still creating an exception.
It's possible that SAP create a detailed exception on creating dynamic queryes or the use of the addCondition method ?
Best Regards,
David Faustini
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.