I'm trying to find a way to have a lookup field on a form to bring
back records from different companies with a simple condition. "Easy"
example i'm trying to execute is listing all male employees across all
companies. I found about the crossCompany keyword but wasn't able to
integrate it into the lookup.
Perhaps my approach isn't right?
Regards,
Masil
There are a number of ways to select cross company, one of them is yours and
is correct.
This seems to work for me (quick test):
public void lookup()
{
SysTableLookup sysTableLookup;
Query query;
;
sysTableLookup = SysTableLookup::newParameters(tablenum(EmplTable),this,
false);
sysTableLookup.addLookupfield(fieldnum(EmplTable, EmplId), true);
query = new Query();
query .allowCrossCompany( true );
query .addCompanyRange( 'CEE' );
query .addCompanyRange( 'CEU' );
query.addDataSource(tablenum(EmplTable));
query.dataSourceTable(tablenum(EmplTable)).addRange(fieldnum(EmplTable,
EmplGender)).value(queryvalue(EmplGender::Male));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
Let me know if it works for you too.
Best regards,
Klaas Deforche.
----------------
http://www.artofcreation.be
"Masil" wrote:
> .
>
Thank you Klaas.
The lookup seems to work indeed. I moved the method directly into the
table though and called it from the form. There are two things i'm
still trying to work on. I get the following message: "The value
'emplid #' in field 'myLookupField' is not found in relating table
'Employee'; this happens if, from the lookup field, I select a record
from a different company then my form is currently in. >>> I have no
idea why it does this
I've then also tweaked it a bit to try retrieving an employee's full
name by joining DirPartyTable and see how it reacts:
static void myLookup(FormControl control)
{
SysTableLookup sysTableLookup;
Query query;
QueryBuildDataSource dsEmplTable;
QueryBuildDataSource dsDirPartyTable;
;
sysTableLookup =
SysTableLookup::newParameters(tablenum(DirPartyTable), control);
sysTableLookup.addLookupfield(fieldnum(DirPartyTable, Name),
true);
query = new Query();
query.allowCrossCompany(true);
query.addCompanyRange('CEE');
query.addCompanyRange('CEU');
dsDirPartyTable = query.addDataSource(tablenum(DirPartyTable));
dsEmplTable = dsDirPartyTable.addDataSource(tableNum(EmplTable));
dsEmplTable.relations(true);
dsEmplTable.joinMode(JoinMode::InnerJoin);
dsEmplTable.addRange(fieldNum(EmplTable,
EmplGender)).value(queryValue(Gender::Male));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
Now by doing this I get the same warning message, though I'm assuming
it would make sense since DirPartyTable.Name isn't part of EmplTable.
Any thoughts?
Regards,
Masil