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

Date from dialog field does not work properly

(0) ShareShare
ReportReport
Posted on by 15

Hi,

I have a problem in a query value when i set the date field  to the date dialog field value the query retrieves all data but when i set it to mkdate(31,1,2019) as an example it filters the data as needed 

Here is my code

//ClassDeclaration

FromDate fromDate;
ToDate toDate;
DialogField dlgFromDate;
DialogField dlgToDate;
#define.CurrentVersion(1)
#localmacro.CurrentList
fromDate,
toDate
#endmacro

//Dialog

public Object dialog(Object _dialog)
{

_dialog.addGroup("@SYS74558");
dlgFromDate = _dialog.addFieldValue(typeid(FromDate),fromDate,"@SYS24050");
dlgToDate = _dialog.addFieldValue(typeid(ToDate),toDate,"@SYS14656");

return _dialog;
}

//getFromDialog

fromDate = dlgFromDate.value();
toDate = dlgToDate.value();

//buildPeriodQuery and add date range (here is the problem)

private Query buildPeriodQuery()
{
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
Query queryBuild;
;
queryBuild = new Query(this.query().pack());

queryBuildDataSource = queryBuild.dataSourceTable(tablenum(CustInvoiceJour));
queryBuildRange = SysQuery::findOrCreateRange(queryBuildDataSource, fieldnum(CustInvoiceJour, InvoiceDate));

queryBuildRange.value(queryRange(fromDate, toDate)); // When i set toDate = mkdate(31,1,2019) it works fine other wise it gets all data ignoring toDate value
info(queryBuildDataSource.toString());
return queryBuild;
}

and this is the query result 

SELECT FIRSTFAST * FROM CustInvoiceJour
WHERE CustTable.AccountNum = CustInvoiceJour.OrderAccount
AND ((RefNum = 0))
AND ((InvoiceDate>={ts '2019-01-01 00:00:00.000'} AND InvoiceDate<={ts '2109-01-31 00:00:00.000'})) // it gets all data the filter of date as it does not exist
JOIN FIRSTFAST * FROM CustInvoiceTrans
WHERE CustInvoiceJour.SalesId = CustInvoiceTrans.SalesId
AND CustInvoiceJour.InvoiceId = CustInvoiceTrans.InvoiceId
AND CustInvoiceJour.InvoiceDate = CustInvoiceTrans.InvoiceDate
AND CustInvoiceJour.numberSequenceGroup = CustInvoiceTrans.numberSequenceGroup

Thanks in advance

I have the same question (0)
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Your code is very difficult to read. Please use Insert > Insert code in the rich formatting view, which preserves indentation and it even supports syntax highlighting (the list of supported languages doesn't include X , but you can use C#, for instance). Look:

    //ClassDeclaration
    FromDate fromDate;
    ToDate toDate;
    DialogField dlgFromDate;
    DialogField dlgToDate;
    
    #define.CurrentVersion(1)
    #localmacro.CurrentList
    fromDate,
    toDate
    #endmacro
    
    //Dialog
    
    public Object dialog(Object _dialog)
    {
    	_dialog.addGroup("@SYS74558");
    	dlgFromDate = _dialog.addFieldValue(typeId(FromDate), fromDate, "@SYS24050");
    	dlgToDate = _dialog.addFieldValue(typeId(ToDate), toDate, "@SYS14656");
    
    	return _dialog;
    }
    
    //getFromDialog
    fromDate = dlgFromDate.value();
    toDate = dlgToDate.value();
    
    //buildPeriodQuery and add date range (here is the problem)
    private Query buildPeriodQuery()
    {
    	Query queryBuild = new Query(this.query().pack());
    	QueryBuildDataSource queryBuildDataSource = queryBuild.dataSourceTable(tablenum(CustInvoiceJour));
    	QueryBuildRange queryBuildRange = SysQuery::findOrCreateRange(queryBuildDataSource, fieldnum(CustInvoiceJour, InvoiceDate));
    
    	queryBuildRange.value(queryRange(fromDate, toDate)); // When i set toDate = mkdate(31,1,2019) it works fine other wise it gets all data ignoring toDate value
    	info(queryBuildDataSource.toString());
    	return queryBuild;
    }

    SELECT FIRSTFAST * FROM CustInvoiceJour
    WHERE CustTable.AccountNum = CustInvoiceJour.OrderAccount
    AND ((RefNum = 0))
    AND ((InvoiceDate>={ts '2019-01-01 00:00:00.000'}
    	AND InvoiceDate<={ts '2109-01-31 00:00:00.000'})) // it gets all data the filter of date as it does not exist
    JOIN FIRSTFAST * FROM CustInvoiceTrans
    WHERE CustInvoiceJour.SalesId = CustInvoiceTrans.SalesId
    AND CustInvoiceJour.InvoiceId = CustInvoiceTrans.InvoiceId
    AND CustInvoiceJour.InvoiceDate = CustInvoiceTrans.InvoiceDate
    AND CustInvoiceJour.numberSequenceGroup = CustInvoiceTrans.numberSequenceGroup

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    What value do you have in toDate variable in buildPeriodQuery()?

  • Khaled_Fahim Profile Picture
    15 on at

    Sorry for inconveniences

    //ClassDeclaration
        FromDate            fromDate;
        ToDate              toDate;
        DialogField         dlgFromDate;
        DialogField         dlgToDate;
        
        #define.CurrentVersion(1)
        #localmacro.CurrentList
           fromDate,
           toDate
        #endmacro
        
    //Dialog
    public Object dialog(Object _dialog)
    {
    
        _dialog.addGroup("@SYS74558");
        dlgFromDate = _dialog.addFieldValue(typeid(FromDate),fromDate,"@SYS24050");
        dlgToDate   = _dialog.addFieldValue(typeid(ToDate),toDate,"@SYS14656");
    
        return _dialog;
    }
    
    //getFromDialog
    public boolean getFromDialog()
    {
        ;
        fromDate = DateStartMth(dlgFromDate.value());
        toDate   = endmth(dlgToDate.value());
    
        return true;
    }
    
    private Query buildPeriodQuery()
    {
        QueryBuildDataSource    queryBuildDataSource;
        QueryBuildRange         queryBuildRange;
        Query                   queryBuild;
        ;
        queryBuild              = new Query(this.query().pack());
    
        queryBuildDataSource    = queryBuild.dataSourceTable(tablenum(CustInvoiceJour));
        queryBuildRange         = SysQuery::findOrCreateRange(queryBuildDataSource, fieldnum(CustInvoiceJour, InvoiceDate));
        //when I set toDate = mkdate(31,1,2019) it works fine other wise it gets data without toDate range
        queryBuildRange.value(queryRange(fromDate, toDate));
        info(queryBuildDataSource.toString());
        return queryBuild;
    }
    
    //info query result with toDate
    SELECT FIRSTFAST * FROM CustInvoiceJour
        WHERE CustTable.AccountNum = CustInvoiceJour.OrderAccount
        AND ((RefNum = 0))
        AND ((InvoiceDate>={ts '2019-01-01 00:00:00.000'} AND InvoiceDate<={ts '2109-01-31 00:00:00.000'}))
        JOIN FIRSTFAST * FROM CustInvoiceTrans
        WHERE CustInvoiceJour.SalesId = CustInvoiceTrans.SalesId
        AND CustInvoiceJour.InvoiceId = CustInvoiceTrans.InvoiceId
        AND CustInvoiceJour.InvoiceDate = CustInvoiceTrans.InvoiceDate
        AND CustInvoiceJour.numberSequenceGroup = CustInvoiceTrans.numberSequenceGroup
     

  • Khaled_Fahim Profile Picture
    15 on at

    toDate   = dlgToDate.value(); //31-01-2019

  • Verified answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Do you want to say that *after* that line, toDate contains a data value representing 31 January 2019?

    Are you 100% sure that it's 2019 and not 2109 (which you have in the resulting query string)?

  • Khaled_Fahim Profile Picture
    15 on at

    toDate.png

  • Khaled_Fahim Profile Picture
    15 on at

    And this is whats happens when i go through query Run next()

    it loops until 2020 

    Fetch.png

  • Verified answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Thank you, your screenshot proves that I was right and you overlooked the problem. The year is indeed 2109, not 2019.

  • Khaled_Fahim Profile Picture
    15 on at

    Many thanks ^_^

    I'm over 3 days trying to solve this.

    I think I need to change my glasses ^_^

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
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans