How to write a Dynamic Query in DP Class to Fetch all the Data if there is no Report Parameter?

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 

    • Create the classes which are required for SSRS report. 
    • Data contract class: It is especially useful for managing parameters in batch jobs and custom services. 
    • Data Provider class: It is used primarily to supply data to SSRS (SQL Server Reporting Services) reports. 
    • Data Controller Class: It is used to manage the execution flow of SSRS reports. 
    • To check the report where no parameter is required we need to change in DP class. 

    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.