How to write a lookup method for filtering and excluding values using a container. 

High level resolution steps 

    Scenario

    Write a lookup method for excluding values using a container, you need to initialize a query for the relevant table, use a container to specify which IDs to exclude, and then display the filtered results in a user-friendly interface. 

    Detailed resolution steps 

      Step 1: Goto ->Form->Datasource->Field ->Right click -> override -> lookup. 

      Step 2: write the below code for lookup. 

      
      public void lookup(FormControl _formControl, str _filterStr)
      {
          Query                   query = new Query();
          QueryBuildDataSource    queryBuildDataSource;
          QueryBuildRange         queryBuildRange;
          
          SCC_PropertyTable       propertyTable, sPropertyTable;
      
          SysTableLookup          sysTableLookup = 
          SysTableLookup::newParameters(tableNum(EntAssetFunctionalLocation), _formControl);
      
          queryBuildDataSource = query.addDataSource(tableNum(EntAssetFunctionalLocation));
          queryBuildRange = queryBuildDataSource.addRange(fieldNum(EntAssetFunctionalLocation, 
          FunctionalLocationID));
      
          queryBuildRange.value(SCC_PropertyHelper::
          getQueryValueFieldPropertyID(SCC_PropertyTable.DeliveryType));
      
          sysTableLookup.addLookupField(fieldNum(EntAssetFunctionalLocation, FunctionalLocationID));
          sysTableLookup.addLookupField(fieldNum(EntAssetFunctionalLocation, Name));
          sysTableLookup.addLookupField(fieldNum(EntAssetFunctionalLocation, FunctionalLocationType));
          sysTableLookup.addLookupField(fieldNum(EntAssetFunctionalLocation, ParentFunctionalLocation));
          sysTableLookup.addLookupField(fieldNum(EntAssetFunctionalLocation, FunctionalLocationLifecycleState));
      
          sysTableLookup.parmQuery(query);
          sysTableLookup.performFormLookup();
      }
      
          

      Code Explanation: 

      Step 3: create a new class as “SCC_PropertyHelper”

      Step 4: write the below code 

      
      internal final class SCC_PropertyIdHelper
      {
          public static str getQueryNotValueForExcludedPropertyID(SCC_DeliveryCode _deliveryCode)
          {
              container               excludedValues;
              SCC_PropertyTable       propertyTable;
              EntAssetFunctionalLocation entAssetFunctionalLocation;
      
              while select propertyTable
                  where propertyTable.DeliveryType == _deliveryCode
              {
                  while select entAssetFunctionalLocation
                      where entAssetFunctionalLocation.FunctionalLocationId == propertyTable.PropertyId
                         && entAssetFunctionalLocation.FunctionalLocationActive == NoYes::Yes
                  {
                      excludedValues += entAssetFunctionalLocation.FunctionalLocationId;
                  }
              }
      
              return queryNotValueCon_W(excludedValues);
          }
      }
      
          

      Code Explination: 

      internal final class SCC_PropertyIdHelper 

          [QueryRangeFunction] 
          public static str getQueryNotValueForExcludedPropertyID(SYN_DeliveryCode _deliveryCode) 
          { 
              container                   excludedValues; 
              SCC_PropertyTable           propertyTable; 
              EntAssetFunctionalLocation  entAssetFunctionalLocation; 
       
              while select propertyTable 
                  where propertyTable.DeliveryType == _deliveryCode 
              { 
                  while  select entAssetFunctionalLocation 
                      where entAssetFunctionalLocation.FunctionalLocationId == propertyTable.PropertyId 
                      && entAssetFunctionalLocation.FunctionalLocationActive == NoYes::Yes 
                  { 
                      excludedValues += entAssetFunctionalLocation.FunctionalLocationId; 
                  } 
              } 
              return queryNotValueCon_W(excludedValues); 
          } 
       

      Output 

        Pass the values in Dialog Click on Ok button. 

        Leave a Reply

        Your email address will not be published. Required fields are marked *