Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

In X++ Report validation

(0) ShareShare
ReportReport
Posted on by 1,215

Hi guys,

i have a enum 3 element if i select "Activeworker"

1.Active worker

By default, report period starts from January up to end of current month

We will show all worker valid to greater than or equal report to date.

From data will be first of January up end of current month date.

how to achieve in X++? in report.

Thanks 

  • Suggested answer
    vinitgoyal2005 Profile Picture
    6,330 on at
    RE: In X++ Report validation

    Hi,

    No it would be between line query = this.parmQuery(); and  queryRun = new QueryRun(query);

    Understnad what this does, you are adding the filter on the query just like select * from SalesTable and with filter it would be Select * from SalesTable where salesid = 'XYZ'. This is exactly what you do with QueryRange.

  • Riyas ahamed F Profile Picture
    1,215 on at
    RE: In X++ Report validation

    thanks for your answer,

    in above your code in while loop inside ?

  • Verified answer
    vinitgoyal2005 Profile Picture
    6,330 on at
    RE: In X++ Report validation

    Hi,

    where are you using the values of fromDate and toDate in your code?

    I assume you will have to do something like below 

    if( employmentStatus == MPEmploymentStatus::Active)
    		{
    			fromDate = //1st January of current year; 
    		}
    		
    		QueryBuildDataSource qbds = query.datasource();
    		qbds.addRange(fieldnum(,)).value(queryRange(fromDate, toDate));

    It is not complete code, you will have to update it where you want to apply the filter. so when QueryRun is executing it will loop on filtered records.

  • Riyas ahamed F Profile Picture
    1,215 on at
    RE: In X++ Report validation

    /// 
    /// The MPWorkerEmploymentDP class declares the variables that are required for the
    /// MPWorkerEmploymentDP report.
    /// 
    [
       SRSReportParameterAttribute(classstr(MPWorkerEmploymentContract)) ,
       SRSReportQueryAttribute(queryStr(MPWorkerEmployment))
    ]
    class MPWorkerEmploymentDP extends SrsReportDataProviderPreProcessTempDB
    {
        MPWorkerEmplymentTmp workerEmplymentTmp;
    
        /// 
        /// Retrieves the data from the MPWorkerEmplymentTmp table for the report.
        /// 
        /// 
        /// The MPWorkerEmplymentTmp table.
        /// 
        [
        SRSReportDataSetAttribute(tableStr(MPWorkerEmplymentTmp))
        ]
        public MPWorkerEmplymentTmp getMPWorkerEmplymentTmp()
        {
            select workerEmplymentTmp;
            return workerEmplymentTmp;
        }
    
        /// 
        ///
        /// 
        public void processReport()
        {
           
            Query                       query;
            QueryRun                    queryRun;
            HcmWorker                   worker;
            HcmPersonPrivateDetails     personPrivateDetails;
            MPLegalCommitment           legalCommitment;
            HcmEmployment               employment;
            RecordInsertList            recordInsertList;
            FromDate                    fromDate;
            ToDate                      toDate;
            MPEmploymentStatus          employmentStatus;
            MPWorkerEmploymentContract  contract;
    
            contract            = this.parmDataContract() as MPWorkerEmploymentContract;
            fromDate            = contract.parmFromDate();
            toDate              = contract.parmToDate();
            employmentStatus    = contract.parmMPEmploymentStatus();
    
            recordInsertList = new RecordInsertList(workerEmplymentTmp.TableId, true, true, true, false, true, workerEmplymentTmp);
            this.takeOwnershipOfTempTable(workerEmplymentTmp);
    
            query = this.parmQuery();
            queryRun = new QueryRun(query);
            while(queryRun.next())
            {
                worker = queryRun.get(tableNum(HcmWorker));
                personPrivateDetails = queryRun.get(tableNum(HcmPersonPrivateDetails));
                legalCommitment = queryRun.get(tableNum(MPLegalCommitment));
                employment = queryRun.get(tableNum(HcmEmployment));
    
                workerEmplymentTmp.PersonnelNumber = worker.PersonnelNumber;
                workerEmplymentTmp.BirthDate = personPrivateDetails.BirthDate;
                workerEmplymentTmp.Nationality = personPrivateDetails.NationalityCountryRegion;
                workerEmplymentTmp.Gender    = personPrivateDetails.Gender;
                workerEmplymentTmp.JoiningDate = employment.ValidFrom;
                workerEmplymentTmp.EmploymentType = employment.EmploymentType;
                workerEmplymentTmp.GrossSalary = legalCommitment.GrossSalary;
               
                recordInsertList.add(workerEmplymentTmp);
            }
            recordInsertList.insertDatabase();
        }
    
    }

    my contract class

    [
        DataContractAttribute
    ]
    class MPWorkerEmploymentContract
    {
        private MPEmploymentStatus employmentStatus;
        FromDate fromDate;
        ToDate toDate;
    
    
    
        [
            DataMemberAttribute('FromDate')
        ]
        public FromDate parmFromDate(FromDate _fromDate = fromDate)
        {
            fromDate = _fromDate;
    
            return fromDate;
        }
    
        [
            DataMemberAttribute('ToDate')
        ]
        public ToDate parmToDate(ToDate _toDate = toDate)
        {
            toDate = _toDate;
    
            return toDate;
        }
    
        [DataMemberAttribute]
        public MPEmploymentStatus parmMPEmploymentStatus(MPEmploymentStatus _employmentStatus = employmentStatus)
        {
            employmentStatus = _employmentStatus;
            return employmentStatus;
        }
    
        /// 
        ///
        /// 
        public boolean validate()
        {
            boolean ret = true;
    
            if (fromDate != dateNull() && toDate != dateNull() && fromDate > toDate)
            {
                ret = checkFailed("@SYS91020");
            }
            if (!fromDate || !toDate)
            {
                //Both dates must be filled in.
                ret = checkFailed("@SYS71110");
            }
            if (ret)
            {
                if (dateStartMth(fromDate) > dateEndMth(toDate))
                {
                    //From date cannot be greater than To date.
                    ret = checkFailed("@SYS120590");
                }
            }
            return ret;
        }
    
    }

    here is how i can write in 

    1.status if it "Active worker"

    • By default, report period starts from January up to end of current month
    • We will show all worker valid to greater than or equal report to date.

    2.

    • status if its "Joiners workers"
    • By default, report period starts from January up to end of current month
    • We will show all worker valid to<> report from date and>from report date.

    Thanks 

  • Suggested answer
    vinitgoyal2005 Profile Picture
    6,330 on at
    RE: In X++ Report validation

    Hi,

    Below is just an example I searched in AOT where the value from the contract is used to update the query. you will need to do the same in your report. I am not sure what do you mean by validation. it is not validation but query manipulation.

    pastedimage1602590679714v1.png

    you will find many more examples like this in OOB reports.

  • Riyas ahamed F Profile Picture
    1,215 on at
    RE: In X++ Report validation

    Thanks for your replay vinit,

    yes!! is it custom report and i need it example of the validation.

  • Suggested answer
    vinitgoyal2005 Profile Picture
    6,330 on at
    RE: In X++ Report validation

    Hi Riyas,

    Is this custom report or OOB report? In your DP class where Query is getting initialized, you need to add/set the range for the date depending on the value from the contract. you will many examples in D365FO OOB reports for this. Please check those and if you still face issues, then please share your code and details about the report.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,165 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,968 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans