web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
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 

I have the same question (0)
  • Suggested answer
    vinitgoyal2005 Profile Picture
    6,332 on at

    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.

  • Riyas ahamed F Profile Picture
    1,215 on at

    Thanks for your replay vinit,

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

  • Suggested answer
    vinitgoyal2005 Profile Picture
    6,332 on at

    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

    /// 
    /// 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 

  • Verified answer
    vinitgoyal2005 Profile Picture
    6,332 on at

    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

    thanks for your answer,

    in above your code in while loop inside ?

  • Suggested answer
    vinitgoyal2005 Profile Picture
    6,332 on at

    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.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 738

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 453 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 286 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans