How to lookup with 2 datasource

Hallo everyone,

i have a requirement for a lookup VendTable and Custable on the form.
and i have 4 display menu items, so i want to give the condition for each menu items.

public void lookup()
        {
            Query query;
            SysTableLookup              sysTableLookup;
            MenuFunction                 menuFunction;
            QueryBuildDataSource     qbds1, qbds2;
            TOC_IdnTaxTransactionJour       idntaxjour;
            TOC_IdnTaxTaxType                  idntaxtype;
            super();
            ;

            sysTableLookup = SysTableLookup::newParameters(tableNum(VendTable), this);
            //sysTableLookup = SysTableLookup::newParameters(tableNum(CustTable), this);

            if(idntaxtype.IdnTaxTypeTax == TOC_IdnTaxTypeTax::WHT_In)
            {
                sysTableLookup.addLookupfield(fieldNum(VendTable, AccountNum));
                sysTableLookup.addLookupfield(fieldNum(VendTable, InvoiceAccount));
            }
            else if(idntaxtype.IdnTaxTypeTax == TOC_IdnTaxTypeTax::WHT_Out)
            {
                sysTableLookup.addLookupfield(fieldNum(CustTable, AccountNum));
                sysTableLookup.addLookupfield(fieldNum(CustTable, InvoiceAccount));
            }
 
            query = new Query();
 
            qbds1 = query.addDataSource(tableNum(VendTable));
            qbds2 = qbds1.addDataSource(tableNum(CustTable));
            qbds2.joinMode(JoinMode::InnerJoin);
            qbds2.relations(true);
            qbds2.addLink( fieldNum(VendTable, AccountNum), fieldNum(CustTable, VendAccount));
 
            sysTableLookup.parmQuery(query);
 
            sysTableLookup.performFormLookup();
        }

i try to use this code but give me an error message “Error executing code: FormRun (object), method selectMode called with invalid parameters.”

any suggest to solve this?

There are several bugs in your code, but I suspect the error is caused by something else.

Try it with simpler code:

public void lookup()
{
    SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(VendTable), this);

    sysTableLookup.addLookupfield(fieldNum(VendTable, AccountNum));
    sysTableLookup.addLookupfield(fieldNum(VendTable, InvoiceAccount));
    sysTableLookup.parmQuery(query);

    sysTableLookup.performFormLookup();
}

Do you still see the error? If so, please tell us more about your scenario. You mentioned some menu items and conditions, but nothing like that is your code. Also, what’s the type of the form control where you added this lookup() method?

Halo Martin,

I have 4 display menu items on 1 form with same datasource which is TOC_IdnTaxTransactionJour.

Display menu items :

  1. TOC_IdnTaxWHTInTrans
  2. TOC_IdnTaxWHTOutTrans
  3. TOC_IdnTaxVATInTrans
  4. TOC_IdnTaxVATOutTrans

So i need the condition for lookup invoice acount field.

If the display menu items is number 1 & 3 , i lookup VendTable field AccountNum and InvoiceAccount.

If the display menu itwms is number 2 & 4, i lookup CustTable field AccountNum and InvoiceAccount.

The type of my form control is string btw

All right, thank for confirming the type of the control. Now please act on the rest of my reply. Test the code I gave you and if it proves that your problem is caused by something else, describe the rest of your implementation to us.
We can’t identify the problem if you don’t give us enough information about your implementation.

Now the message is “more than one form was opened at once for the lookup control”

As I said, I can’t help you unless you provide more information about your implementation. It’s up to you.

I just want to know how to give a condition for each display menu items above.

When i open TOC_IdnTaxVATInTrans and TOC_IdnTaxWHTInTrans the field invoice account will lookup to the VendTable.

But when i open TOC_IdnTaxVATOutTrans and TOC_IdnTaxWHTOutTrans the field invoice account will lookup to the CsustTable.

I’m sorry, but I can’t help you without more information from you.