Tuesday, September 17, 2013

Lookup Code Samples

1.Simple lookup by Overriding Lookup method of string field

public void lookup(FormControl _formControl, str _filterStr)
{
    Query                   query          = new Query();
    SysTableLookup          sysTableLookup =  SysTableLookup::newParameters(tableNum(ProjTable),_formControl);
    ;    query.addDataSource(tableNum(ProjTable)).addRange(fieldNum(ProjTable,Type)).value(queryValue(ProjType::Internal));
    sysTableLookup.addLookupField(fieldNum(ProjTable, ProjId));
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
    //super(_formControl, _filterStr);
}

2.Lookup Using Exists Join

public void lookup()
{
  Query                   query = new Query();
  QueryBuildDataSource    qbds,qbds1;
  // Instantiate sysTableLookup object using table which will provide the visible fields
  SysTableLookup  sysTableLookup = sysTableLookup::newParameters(tableNum(DirPartyRelationship), this);
  ;
  qbds = query.addDataSource(tableNum(DirPartyRelationship));
  qbds.addRange(fieldNum(DirPartyRelationship,RelationshipTypeId)).value("Child");
  qbds.addRange(fieldNum(DirPartyRelationship,ParentParty)).value(queryValue(CEMPayrollInvoiceDetails.Person));
  qbds1 =qbds.addDataSource(tableNum(CEMPayrollInvoiceDetails));
  qbds1.relations(true);
  qbds1.joinMode(JoinMode::ExistsJoin);
  // Set the query to be used by the lookup form
  sysTableLookup.parmQuery(query);
  // Specify the fields to show in the form.
  sysTableLookup.addLookupfield(fieldNum(DirPartyRelationship,ChildParty));
  // Perform the lookup
  sysTableLookup.performFormLookup();

}

3.Lookup Using Exists Join Sample 2

public void lookup(FormControl _formControl, str _filterStr)
{
    WrkCtrTable wrkCtrTable;

    Query                   query          = new Query();
    QueryBuildDataSource    WrkCtrTableds,WrkCtrResourceGroupResourceds,WrkCtrResourceGroupds;
    SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tableNum(WrkCtrTable), _formControl);
    ;

    WrkCtrTableds = query.addDataSource(tableNum(WrkCtrTable));

    WrkCtrTableds.addRange(fieldNum(WrkCtrTable,WrkCtrType)).value(queryValue(WrkCtrType::Machine));

    WrkCtrResourceGroupResourceds = WrkCtrTableds.addDataSource(tableNum(WrkCtrResourceGroupResource));

    WrkCtrResourceGroupResourceds.relations(true);
    WrkCtrResourceGroupResourceds.joinMode(JoinMode::ExistsJoin);

    WrkCtrResourceGroupds = WrkCtrResourceGroupResourceds.addDataSource(tableNum(WrkCtrResourceGroup));
    WrkCtrResourceGroupds.addRange(fieldNum(WrkCtrResourceGroup,InputInventLocationId)).value(queryValue(SalesLine.inventDim().InventLocationId));

    WrkCtrResourceGroupds.relations(true);
    WrkCtrResourceGroupds.joinMode(JoinMode::ExistsJoin);

    sysTableLookup.addLookupField(fieldNum(WrkCtrTable, WrkCtrId));
    sysTableLookup.addLookupField(fieldNum(WrkCtrTable, Name));
    
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();

    //super(_formControl, _filterStr);

}

4.Lookup overriding lookupReference method of Reference field

public Common lookupReference(FormReferenceControl _formReferenceControl)

{
    SysReferenceTableLookup sysTableLookup = SysReferenceTableLookup::newParameters(tableNum(EcoResCategory),_formReferenceControl);

    Query testQuery;

    QueryBuildDataSource qbds;

    QueryBuildRange qbr;

    EcoResCategory selectedRecord;

    // Display the coulmns fields in the lookup form.

    sysTableLookup.addLookupfield(fieldNum(EcoResCategory, Name));

    //sysTableLookup.addLookupfield(fieldNum(EcoResCategory, RecId));

    // Create a custom Query

    testQuery= new Query();

    qbds = testQuery.addDataSource(tableNum(EcoResCategory));

    qbr = qbds.addRange(fieldNum(EcoResCategory, CategoryHierarchy));

    qbr.value(queryValue(dialogCategoryHierarchy.value()));

    qbr = qbds.addRange(fieldNum(EcoResCategory, ParentCategory));

    qbr.value(queryValue(0));

    sysTableLookup.parmQuery(testQuery);

    selectedRecord = sysTableLookup.performFormLookup();


    return selectedRecord;
}

No comments:

Post a Comment

Beautiful Fish Tank