Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Multi company lookup field

92 views
Skip to first unread message

Masil

unread,
Jul 12, 2010, 9:57:56 AM7/12/10
to
Greetings,

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

Klaas Deforche

unread,
Jul 13, 2010, 4:14:05 AM7/13/10
to
Hi 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:

> .
>

Masil

unread,
Jul 14, 2010, 5:29:23 PM7/14/10
to
On Jul 13, 4:14 am, Klaas Deforche

<KlaasDefor...@discussions.microsoft.com> wrote:
> Hi 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:
> > Greetings,
>
> > 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
> > .

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

0 new messages