Method error

hI,

With the below method i need to know how to get the start date

if (ret)
{
caepr1 =CaePR::find(this.EmplId);
select caeStartDate from caepr1 where caepr1.EmplId == this.EmplId;
if (caepr1.caeStartDate == this.caeStartDate)
{
ret = ret && checkFailed(“Start Daet already exists”);
}
}

Like am always getting the start date as the first field start date from the grid.But i need get the start date from the query

select caeStartDate from caepr1 where caepr1.EmplId == this.EmplId; I dont know how to call it.

Regards,

Sindhu

Hi,

I have a table called PR .Here we have employee id and start date.For single employee id ,it should not duplicate the start date.With the above method always it is checking with the first start date of the employee.I want the method to loop all the start date of the particular employee and if the start date exist it should pop a message.

Regards,

Sindhu

caepr1 =CaePR::find(this.EmplId);

// Find matching record if any
select firstonly caepr1
where caepr1.EmplId == this.EmplId;
&& caepr1.caeStartDate == this.caeStartDate;

// matching record found
if (caepr1.recId)
{

ret = ret && checkFailed(“Start Daet already exists”);
}

…guys, where’s the point calling a find() method (basically a select statement) and then in the following code lines to do a select with the same table buffer once again? Basically CaePR::find() is called and you don’t even care what it returned, you just use the same buffer for the next select statement.

Thanks a lot for the response.

But i wrote a method to loop the start date.i think it worked.

boolean ret;
CaePR caepr1;
ret = super();

if (ret)
{
while select forupdate caepr1 where caepr1.EmplId == this.EmplId
{
if ( this.caeStartDate == caepr1.caeStartDate)
{
ret = ret && checkFailed("@CAE97");
}
}
}

return ret;

Thanks a lot for the response.

But i wrote a method to loop the start date.i think it worked.

boolean ret;
CaePR caepr1;
ret = super();

if (ret)
{
while select forupdate caepr1 where caepr1.EmplId == this.EmplId
{
if ( this.caeStartDate == caepr1.caeStartDate)
{
ret = ret && checkFailed("@CAE97");
}
}
}

return ret;

Yes it works but this is not a best practice. Using a loop with if statement is longer than using a select with several where clauses. Moreover if you just need to check if a record exists, you must select a list of fields instead of the record itself. Write the code bellow without the find() method:

select firstonly RecId from caepr1
where caepr1.EmplId == this.EmplId;
&& caepr1.caeStartDate == this.caeStartDate;

if (caepr1.recId)
{

ret = ret && checkFailed(“Start Date already exists”);
}

Regards,

Florent

Thanks Florent .I have changed the code without having while loop.