Alex Kwitny
Alex Kwitny

Reputation: 11544

Lookup method bug with SysTableLookup?

This is code that should work with any base system added to Tables\ProdBOM. Somehow the query is stripping out data from fields.

static void lookupItemIdBOMSubset(FormStringControl   _ctrl,
                                  ProdId              _prodId)
{
    SysTableLookup          sysTableLookup  = SysTableLookup::newParameters(tableNum(ProdBOM), _ctrl);
    Query                   query           = new Query();
    QueryBuildDataSource    qbds            = query.addDataSource(tableNum(ProdBOM));
    ;

    qbds.addRange(fieldNum(ProdBOM, ProdId)).value(queryvalue(_prodId));
    qbds.addSortField(fieldNum(ProdBOM, LineNum), SortOrder::Ascending);

    sysTableLookup.parmQuery(query);

    sysTableLookup.addLookupfield(fieldNum(ProdBOM, LineNum));
    sysTableLookup.addLookupfield(fieldNum(ProdBOM, BOMId));
    sysTableLookup.addLookupfield(fieldNum(ProdBOM, ItemId), true);

    // This doesn't work \/
    sysTableLookup.addLookupMethod(tablemethodstr(ProdBOM, configId));
    // This doesn't work /\

    sysTableLookup.addLookupMethod(tablemethodstr(ProdBOM, itemName));
    sysTableLookup.addLookupfield(fieldNum(ProdBOM, ProdLineType));
    sysTableLookup.addLookupfield(fieldNum(ProdBOM, InventTransId));

    sysTableLookup.performFormLookup();
}

In the Tables\ProdBOM\Methods\configId, you can clearly see something is awry with this code. What's going on??

//BP Deviation documented
display ConfigId configId()
{
    ProdBOM pb;
    ;
    select firstonly pb where pb.RecId == this.RecId;

    info(strfmt("Bad: [%1, %2], Good:[%3, %4]", this.ItemId, this.InventDimId, pb.ItemId, pb.InventDimId));
    return this.inventDim().ConfigId;
}

Upvotes: 2

Views: 2584

Answers (2)

Doc
Doc

Reputation: 491

You can force the QueryBuildDatasource to load needed fields by modifying its fieldlist. You can use QueryBuildDatasource.fields().addField() method to add fields wich schould be fetched and are in use by your LookupMethod

Upvotes: 1

Alex Kwitny
Alex Kwitny

Reputation: 11544

So I figured it out. In Classes\SysTableLookup\buildSelectionList, it adds all of the fields that are included in the lookupfields to the QBDS.addSelectionField, which appears to drop it off the return fields??

It doesn't strip out RecId though, so I was able to just create another display method that re-selects the record using the recId.

//BP Deviation documented
display ConfigId configIdFromRecId()
{
    return InventDim::find((select firstonly prodBOM where prodBOM.RecId == this.RecId).InventDimId).configId;
}

Upvotes: 4

Related Questions