How to write dynamic query in DP class to fetch all the data if there is no Report Parameter? 

Scenario:  If the user does not specify any parameters in the report, it should display all records by default. 

High Resolution steps 

    Detailed Resolution steps 

      Step 1: SCEContractDPReportDP Process report() 

      Code: 

      Code Snippet: 

      public void processReport() 
      
        { 
      
            Query                           query          = new Query(); 
      
            QueryBuildDataSource            qbdsHcmWorker, qbdsHcmEmployment, qbdsCompanyInfo; 
      
            QueryBuildRange                 qbr,qbs; 
      
            Hcmworker                       hcmWorker; 
      
            SCEContractDPReportContract     contract        = this.parmDataContract(); 
      
            HcmPersonnelNumberId            personnelNumber = contract.parmHcmPersonnelNumberId(); 
      
       
      
            if (personnelNumber) 
      
            { 
      
                hcmWorker  = Hcmworker::findByPersonnelNumber(personnelNumber); 
      
       
      
                this.Insertdata(hcmWorker); 
      
            } 
      
            else 
      
            { 
      
                qbdsHcmWorker         = query.addDataSource(tablenum(HcmWorker)); 
      
                qbdsHcmEmployment     = qbdsHcmWorker.addDataSource(tablenum(HcmEmployment)); 
      
               
      
                qbdsHcmEmployment.joinMode(JoinMode::InnerJoin); 
      
                qbdsHcmEmployment.relations(true); 
      
                qbdsCompanyInfo = qbdsHcmEmployment.addDataSource(tableNum(CompanyInfo)); 
      
                qbdsCompanyInfo.relations(true); 
      
                qbdsCompanyInfo.joinMode(JoinMode::InnerJoin); 
      
       
      
                qbr = qbdsHcmEmployment.addRange(fieldnum(HcmEmployment,EmploymentType)); 
      
                qbr.value(queryValue(HcmEmploymentType::Contractor)); 
      
       
      
                qbs = qbdsCompanyInfo.addRange(fieldnum(CompanyInfo,DataArea)); 
      
                qbs.value(queryValue(curExt())); 
      
                   
      
                QueryRun qr = new QueryRun(query); 
      
            
      
                 while (qr.next()) 
      
                { 
      
                    hcmWorker = qr.get(tableNum(HcmWorker)); 
      
                  
      
                    this.Insertdata(hcmWorker); 
      
                } 
      
            } 
      
        } 

      NOTE: The above Code Snippet provides the dynamic query where this is written because whenever the user does not provide parameters it should display all the records. 

      Output 

        The above screenshot represents that in the parameter we are not giving any value. 

        The report will generate all the records when we don’t provide the parameters. 

        The report when provided on the parameter of specific Personnel Number it should fetch only that record.  

        The report provided with specific record of PersonnelNumber. 

        Leave a Reply

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