Skip to main content

Notifications

How to use temporary table as a datasource for lookup in form

Temporary table as a lookup datasource
 
We may sometimes encounter a situation where we need to use a temporary table as a datasource in a form lookup. But this is a bit tricky because it gets data on runtime, and we can't just do it in normal way like how we do for regular tables. So, this requires runtime insert of data as a temporary table doesn't contain data stored and should trigger lookup.
 
 
Business Scenario:
 
Let's say we have a requirement where we have some constant variables which are defined in a class as constants, and we need to give them as a lookup instead of hard coding from UI by user. As those are not enums and defined in class what I did is I inserted them to a temporary table called Inmemory table here and did the further coding of lookup. Main important thing here in we need to pass the temporary table buffer into SysTableLookup objects by using parmTmpBuffer() method.
 
 
Here is the code for the same. 
 
public void lookup(Object _object)
{
    EmailFieldsTmp  temp;


    temp.EmailFieldName = SendEmail::CustomerName;
    temp.insert();

    temp.EmailFieldName = SendEmail::CustomerManagerName;
    temp.insert();
 
 
    SysTableLookup              sysTableLookup = SysTableLookup::newParameters(tablenum(EmailFieldsTmp), _object);
    Query                       query = new Query();
    QueryBuildDataSource        queryBuildDataSource;

    queryBuildDataSource = query.addDataSource(tablenum(EmailFieldsTmp));
    sysTableLookup.addLookupfield(fieldnum(EmailFieldsTmp, EmailFieldName), true);
 
    sysTableLookup.parmQuery(query);
    sysTableLookup.parmTmpBuffer(temp);
    sysTableLookup.performFormLookup();
}
 
Here I just added some randomized constants with some values which will be shown for lookup. But in general if we have some set of data, we can loop and show that and assign that to SysTableLookup object. In this way this is achievable.
 
 
 
 
 
 
Please post for any questions and happy learning!
 

Comments