How to create a lookup with fields from more than one datasource?

只愿长相守 提交于 2020-01-01 15:35:10

问题


I need to create Dynamic lookup in my form field which should display fields from two different datasources.. I am trying to perform it as:

  public void lookup()
  {

    query = new Query();
   sysTableLookup = SysTableLookup::newParameters(tableNum(smmBusRelTable), this);
  qbds = query.addDataSource(tablenum(smmBusRelTable));
 // qbds.addDataSource(tableNum(DirPartyTable));
 //qbds.relations(true);

sysTableLookup.parmQuery(query);   
sysTableLookup.addLookupField(fieldNum(smmBusRelTable, Busrelaccount));
//sysTableLookup.addLookupfield(fieldNum(DirPartyTable, Name));


 sysTableLookup.performFormLookup();
}

Commented lines are the operation I am trying to perform to add different datasource.


回答1:


As far as I know the SysTableLookup class does not support showing fields from other tables. The addLookup() method doesn't take a TableId and assumes all fields are in the first datasource of the query.

You could write your own version of SysTableLookup that supports referencing fields from various tables. A simpler and more practical (and less expensive) approach might be to create a display method on SmmBusRelTable to fetch the name from DirPartyTable (if it doesn't already exists) and use that as a field in the lookup. Display methods on the main table are supported if I remember correctly.

Depending on what exactly you're trying to accomplish there might be an even simpler way. You could add the display method to the AutoLookup table field group of SmmBusRelTable and avoid having to override the lookup() method.




回答2:


It is actually very easy to combine multiple datasources in a sysTableLookup. Here is the trick I used to be able to filter on the name from the EcoResProductTranslation in the lookup for items.

1) Create a view that combines all your datasources and add the fields you would like to see in your lookup to the view.
2) Create a query from the view created in step 1.
3) Use these to perform your lookup as follows...

static client void lookupItemActive(FormStringControl _ctrl)
{
    SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(<ViewName>),_ctrl);
    Query          query = new Query(queryStr(<QueryName>));

    sysTableLookup.addLookupfield(fieldnum(<ViewName>, ItemId));
    sysTableLookup.addLookupfield(fieldNum(<ViewName>, Name));
    sysTableLookup.addLookupfield(fieldNum(<ViewName>, ItemGroupId));
    sysTableLookup.addLookupfield(fieldnum(<ViewName>, Status));
    sysTableLookup.addLookupfield(fieldnum(<ViewName>, RevId));
    sysTableLookup.addLookupfield(fieldnum(<ViewName>, ItemType));

    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}


来源:https://stackoverflow.com/questions/14659999/how-to-create-a-lookup-with-fields-from-more-than-one-datasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!