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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

In X++ Date validation status based

(0) ShareShare
ReportReport
Posted on by 1,215

Hi guys,

i want to below date validation and i have a Enum status

3 element: Active/Joiner/Leaver

1 if i select Active status   

  • 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.if i select Joiner status

  • By default, report period starts from January up to end of current month
  • We will show all worker valid from <> report from date.

if i select Leaver status

  • 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 

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Riyas,

    Where are you trying to do this validation? While inserting records?

  • Riyas ahamed F Profile Picture
    1,215 on at

    Thanks for your replay,

    i trying in SSRS report,

    /// 
    /// 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;
        }
    
        /// 
        /// Processes the report business logic.
        /// 
        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);
            if(fromDate > (toDate))
            {
                   
            }
            query = this.parmQuery();
            //fromDate = any2Date(mthOfYr(Year()));
    
            if(employmentStatus == MPEmploymentStatus::ActiveWorker)
            {
                
                 
            }
    
            QueryBuildDataSource qbds = query.dataSourceTable(tableNum(HcmEmployment));
            qbds.addRange(fieldnum(HcmEmployment,validfrom)).value(queryRange(fromDate, toDate));
           // query.validTimeStateDateTimeRange(DateTimeUtil::newDateTime(fromDate, DateTimeUtil::time(DateTimeUtil::utcNow())), DateTimeUtil::newDateTime(toDate, DateTimeUtil::time(DateTimeUtil::utcNow())));
            queryRun = new  QueryRun(query);
    
            while(queryRun.next())
            {
                worker               = queryRun.get(tableNum(HcmWorker));
                personPrivateDetails = queryRun.get(tableNum(HcmPersonPrivateDetails));
                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      = worker.grossSalary();
               
                recordInsertList.add(workerEmplymentTmp);
            }
            recordInsertList.insertDatabase();
        }
    
    }

    Thanks

  • Community Member Profile Picture
    on at

    use this code and let me know

    QueryBuildDataSource qbds = query.dataSourceTable(tableNum(HcmEmployment));

    switch(employmentstatus)

    {

    case MPEmploymentStatus::ActiveWorker:

     qbds.addRange(fieldnum(HcmEmployment,validto)).value(queryRange(todate..));

    break;

    case MPEmploymentStatus::Joiner:

     qbds.addRange(fieldnum(HcmEmployment,validfrom)).value(queryRange(fromdate));

    break;

    case MPEmploymentStatus::Learner:

     qbds.addRange(fieldnum(HcmEmployment,validto)).value(queryRange(fromdate..));

    break;

    }

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Riyas,

    So, based on the enum value you want to filter the data to be shown on the report. Correct?

  • Riyas ahamed F Profile Picture
    1,215 on at

    Yess! correct sir.

  • Blue Wang Profile Picture
    on at

    Hi Riyas,

    qbds.addRange(fieldNum(Table, Status))
            .value(queryValue(Yourenum::Active));
    qbds.addRange(fieldNum(Table, StartDate))
            .value(SysQuery::range(_startDate, dateNull()));
    qbds.addRange(fieldNum(Table, EndDate))
            .value(SysQuery::range(dateNull(), _endDate));

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Riyas,

    Can you try this code and check if that works for you?

    /// 
    /// 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;
        }
    
        /// 
        /// Processes the report business logic.
        /// 
        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;
    		QueryBuilRange				dateRange;
    		UTCDateTime					fromDateTime, toDateTime;
    
            contract            = this.parmDataContract() as MPWorkerEmploymentContract;
            fromDate            = contract.parmFromDate();
            toDate              = contract.parmToDate();
            employmentStatus    = contract.parmMPEmploymentStatus();
    		
    		fromDateTime 		= DateTimeUtil::newDateTime(fromDate, 0);
    		toDateTime 		= DateTimeUtil::newDateTime(toDate, 0);
            
            recordInsertList = new RecordInsertList(workerEmplymentTmp.TableId, true, true, true, false, true, workerEmplymentTmp);
            this.takeOwnershipOfTempTable(workerEmplymentTmp);
            if(fromDate > (toDate))
            {
                   
            }
            query = this.parmQuery();
            //fromDate = any2Date(mthOfYr(Year()));
    		
    		QueryBuildDataSource qbds 	= query.dataSourceTable(tableNum(HcmEmployment));
    		
            switch (employmentStatus)
            {
                case MPEmploymentStatus::ActiveWorker:
    				qbds.addRange(fieldnum(HcmEmployment,ValidTo)).value(queryRange(toDateTime, DateTimeUtil::maxValue());
    				break;
    				
    			case MPEmploymentStatus::Joiner:
    				qbds.addRange(fieldnum(HcmEmployment,ValidFrom)).value(queryRange((fromDateTime   1), DateTimeUtil::maxValue());
    				break;
    			
    			case MPEmploymentStatus::Leaver:
    				qbds.addRange(fieldnum(HcmEmployment,ValidTo)).value(queryRange((fromDateTime   1), toDateTime);
    				break;
                 
            }
                         
            queryRun = new  QueryRun(query);
    
            while(queryRun.next())
            {
                worker               = queryRun.get(tableNum(HcmWorker));
                personPrivateDetails = queryRun.get(tableNum(HcmPersonPrivateDetails));
                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      = worker.grossSalary();
               
                recordInsertList.add(workerEmplymentTmp);
            }
            recordInsertList.insertDatabase();
        }
    
    }

  • Riyas ahamed F Profile Picture
    1,215 on at

    Thanks for your answer sir,

    but in above your code utc not + operator am getting errors ?  

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Riyas,

    Please highlight the code and the error you are getting.

  • Riyas ahamed F Profile Picture
    1,215 on at

    utc.PNG

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 456 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans