0

I need to setup range of valid contracts to inform on tile how much are contracts which are expiring in next 3 months. So, every day, when user opens workspace there should be tile which will say exact number of contracts which are expiring in next three months. For that purpose, I need query where I will have date range parameter. I wrote up code, but I missing something. Any suggestion ?

    [Query]
public class PMCCMW_ExpiringContracts extends QueryRun
{
    Query                   query;
    QueryRun                queryRun;
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    PMCContract               pmcContract;
    TransDate startDate,EndDate;

    startDate = today();
    EndDate = DateTimeUtil::addMonths(3);

    query = new Query();

    queryBuildDataSource = query.addDataSource(
        TableNum(PMCContract));

     queryBuildRange = queryBuildDataSource.addRange(
    FieldNum(PMCContract,ValidTo));

     queryBuildRange.value(queryRange(StartDate,EndDate));


    queryRun = new queryRun(query);

    if (queryRun.prompt())
    {
        while (queryRun.next())
        {
            pmcContract= queryRun.get(TableNum(PMCContract));
            print PMCContract.Validto;
        }
    }
}
DarthCSharper
  • 133
  • 1
  • 13
  • 2
    What happens if you instantiate the end date like this: EndDate = DateTimeUtil::date(DateTimeUtil::addMonths(DateTimeUtil::utcNow(), 3)); – rjv Jul 04 '19 at 16:17
  • `PMCContract` seems to be a custom table. Could you [edit] the table definition into your question? Is it a valid time state table? In that case, take a look at [How to: Use the Query Class to Read From a Valid Time State Table](https://learn.microsoft.com/da-dk/dynamicsax-2012/developer/how-to-use-the-query-class-to-read-from-a-valid-time-state-table) – FH-Inway Jul 05 '19 at 13:31
  • 1
    Is `ValidTo` a `utcDateTime` or a `date` field? – Alex Kwitny Jul 05 '19 at 16:25
  • @AlexKwitny date field – DarthCSharper Jul 09 '19 at 12:03
  • 1
    @DarthCSharper - That's obviously the actual issue. Does your code even compile? `EndDate` is a `date` type and `DateTimeUtil::addMonths(3)` doesn't return the same datatype and it's missing required arguments. You need to use something like what @rjv said. Use `endDate = str2Date("10/1/2019", 213);` to test with. – Alex Kwitny Jul 09 '19 at 15:44

0 Answers0