Wednesday, 9 December 2015

how to form a query based on relation

static void newjob(Args _args)
{
    EcoResDistinctProductVariant        EcoResDistinctProductVariant;
    EcoResProductVariantConfiguration   EcoResProductVariantConfiguration;
    EcoResProductMaster                 resproductmaster;
    EcoResConfiguration                 EcoResConfiguration;
    Query                   query = new Query();
    QueryRun                qr;
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildDataSource    queryBuildDataSource2;
    QueryBuildDataSource    queryBuildDataSource3;
    QueryBuildDataSource    queryBuildDataSource4;
    QueryBuildRange         queryBuildRange;
    QueryBuildRange         queryBuildRange2;
    SysTableLookup          sysTableLookup;
    EcoResConfiguration     EcoResConfiguration1;
 
   
    select * from resproductmaster  where resproductmaster.DisplayProductNumber == "SamsungS20";  
   
    while select * from EcoResDistinctProductVariant  where EcoResDistinctProductVariant.ProductMaster == resproductmaster.RecId
    {      
        select * from EcoResProductVariantConfiguration  where EcoResProductVariantConfiguration.DistinctProductVariant == EcoResDistinctProductVariant.RecId;
        select * from EcoResConfiguration  where EcoResConfiguration.RecId == EcoResProductVariantConfiguration.Configuration;
        info(strFmt("%1",EcoResConfiguration.Name));
    }
   
   
    queryBuildDataSource    = query.addDataSource(tableNum(EcoResConfiguration));
    queryBuildDataSource2   = queryBuildDataSource.addDataSource(tableNum(EcoResProductVariantConfiguration));
    queryBuildDataSource2.addLink(fieldNum(EcoResConfiguration, RecId), fieldNum(EcoResProductVariantConfiguration, Configuration));
    queryBuildDataSource3   = queryBuildDataSource2.addDataSource(tableNum(EcoResDistinctProductVariant));
    queryBuildDataSource3.addLink(fieldNum(EcoResProductVariantConfiguration, DistinctProductVariant), fieldNum(EcoResDistinctProductVariant, RecId));
    queryBuildDataSource4   = queryBuildDataSource3.addDataSource(tableNum(EcoResProductMaster));
    queryBuildDataSource4.addLink(fieldNum(EcoResDistinctProductVariant, ProductMaster), fieldNum(EcoResProductMaster, RecId));
    queryBuildDataSource4.addRange(fieldNum(EcoResProductMaster, DisplayProductNumber)).value("Galaxy S Duos Gold");

    qr = new QueryRun(query);
    while(qr.next())
    {
        EcoResConfiguration1 = qr.getNo(1);
        info(EcoResConfiguration1.Name);
    }
   
}

No comments:

Post a Comment

intercompany PO multiple product receipt by x++

public void processStampICPO(PackingSlipId _deliveryNote,                             Transdate _deliverydate,                             ...