Query with no parameters entered from User.

Hey guys,
if i got a query that end user should put at least one parameters into it…
if parameter exist in the query i run the QueryRun.next() to get the values>>

my question is if the end user didnt put any parameters then i dont want to run the Query because the queryrun.next here will select * all the data.

and i dont want it to select anything ill do my own code for that.

Hi,

you can have two seperate methods to do this.

One to perform the query , if the user enters value for the parameter.

Other method to perform your own code , if he doesnt enter any param.

Now, you can call the methods appropriately.

i meant check for the null condition…

and call the methods…

yea thats what i wanted to do,

my code:

while (queryRun.next())

positionTableQ = queryRun.get(tableNum(HRPPartyPositionTableRelationship));

TTSBEGIN;
payrollLine.emplId = emplTable.EmplId;
payrollLine.insert();
TTSCOMMIT;

i want to know how can i check if parameters exist before that code, if any parameter exist then to run the code above, else ill do my own code
how to know if any parameter exist in the queryRun ??? thanks

Hi Noob,

You have not mentioned how you get users to enter/select parameters (i.e. whether through a dialog created by class, an inquiry form through filter field etc).

If it is dialog created by class, you have many options. For example, you can do this in ‘getFromDialog’ method.

If it is filter in inquiry form, you can write validation code on modified method of filter.

Regards,

the query is created in class as a custom query with QuerybuildDatasource and etc…

and the same class is connected to a form so it is a dialog form with the standard form fields + [dialogStartGrp] for the dialog fields or query [ im not using any dialog fields only a query]

some of my class code:

Object dialog()
{
DialogRunbase dialog = Dialog::newFormnameRunbase(formstr(BSF_TmpAllowancesDialog),this);
;
dialog = super(dialog);

return dialog;
}


void new()
{

q = new Query();
qbdsPosition = q.addDataSource(tableNum(HRPPartyPositionTableRelationship));
qbdsEmpl = qbdsPosition.addDataSource(tableNum(EmplTable));
qbdsPosition.allowAdd(2);

qbdsEmpl.joinMode(JoinMode::InnerJoin);
qbdsEmpl.fetchMode(QueryFetchMode::One2Many);
qbdsEmpl.addLink(fieldNum(HRPPartyPositionTableRelationship, Reference),
fieldNum(EmplTable, EmplId));


Void run()
{
;

try
{ //check if query params exist here!! if any parameter exist then do the queryRun.next to get from the parameters, else i will call my own method
while (queryRun.next())
{
positionTableQ = queryRun.get(tableNum(HRPPartyPositionTableRelationship));

while select emplTable where emplTable.EmplId == positionTableQ.Reference
&& emplTable.status == HRMEmplStatus::Employed

{

Hi Noob,

In the form closeOK method, you can add validations. Pseudo code-

if (!validate)
{

}

In the validate method, you can write like this -

boolean validate()
{
boolean ret;
;
ret = true;

if (<some condition)
{
ret = ret && checkFailed();
}

return ret;

Regards,

Harish Mohanbabu

you helped me with the validation process because im coming into it.

but the real problem is when the user input nothing in parameters i must write a code to insert records [for another requirment] not to avoid him from entering no parameters

so when he doesnt input any parameter i should make another proccess, how can i see if the query parameters is NULL?

hi…

sorry… could you please make it a bit clear…

select emplTable where emplTable.EmplId == positionTableQ.Reference
&& emplTable.status == HRMEmplStatus::Employed

which are the params, you expect it to be null in the query…? this will help us help you…

Jayanthi

just forget my code, its just what i need in my process [only logic needed to be done] IF the user clicked the select button and fill any of the parameters shown in the inquiry form.

what is needed when the user DOES NOT fill any parameters, i want to know so i can do another logic needed.

so the quryRun.next will take the parameters entered one by one
if there is no parameters it will select * emplTable for example. and thats what i dont want the query to select all the records, i want it to IGNORE the query and to do my own code [logic]

Thats all about the issue.

thanks

Hey guys thanks for your effort. i found the solution to my case from http://dynamicsuser.net/forums/p/16762/78058.aspx, and i would like to share it for people.

First of all: My Case is i build a custom query in a class and if the user clicked the Select menu button he will fill the parameters with values, then in my run method i wrote the queryRun.next() to get these values and do my needed process according to the query parameters.

if the user didnt fill any of parameters shown, i should know that and i shouldnt call the queryRun.next() because it will get all the records, so im going to build my own proccess if the user didnt select any parameters.

The Question is : how do i know if the user didnt select any parameters from the Inquiry form?
The Answer is : by making a for loop getting the DatasourceCountNo and taking the name and value [it will be more clearer by viewing my code below]

My code:

int j,k,CurFieldID;
boolean empty = true;
;
//check if any query parameters entered from user
for (k=1;k<=queryRun.query().dataSourceCount();k++)
{
for (j=1;j<=queryRun.query().dataSourceNo(k).rangeCount();j++)
{
CurFieldID = fieldname2ID(queryRun.query().dataSourceno(k).table(),queryRun.query().dataSourceNo(k).range(j).name());

if(queryRun.query().dataSourceNo(k).range(j).value())
{
empty = false;
break;
}
}
}
//If there is no parameters
if(empty)
{
this.MyMethod // to do my own logic avoiding the select * from the query
}

//If there is at least one parameter then go to queryRun.next()
else
{
while (queryRun.next())


}