RE: How to list employees within the same department?
You should put the conditions in the select statement, otherwise it's indeed slow.
Now your query loops all workers, and for each of them it asks "is this worker part of Finance department?".
Also, you have unnecessary calls for "HcmWorker::find"is definetely not needed since you already have a HcmWorker at hand inside the while statement.
So, first of all, let's clean out those calls.
static void Job114CR5(Args _args)
{
HcmWorker hcmWorker;
while select hcmWorker
{
if(hcmWorker.getdepartmentname()=='Finance')
{
info(hcmWorker.name());
}
}
}
Then, we want to improve it further since you still do a lot of unnecessary work and lot of database calls, when you would like to have just one query in the database. You should formulate this question as part of the select statement. So, take a look what's inside HcmWorker.getDepartmentName() and move that logic into your select statement.
Eventually you want to have something like this:
while select hcmWorker
where departmentName == "Finance" // You need to formulate here some condition
{
info(hcmWorker.name());
}