Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Set default parameter values

Posted on by Microsoft Employee

Hi,

I have a report that uses a Data Provider. The data provider requires two parameters, "start date" and "end date" which are set in a data contract and passed to the data provider. When the report is published to AX it all works fine. I'm  able to select the start and end date and run the report and see the expected results.

What I would like to do is automatically set the end date to today and the start date to 7 days ago but I cannot figure out how to set default parameter values. Are they set in the contract? Can anyone provide an example or point me to a tutorial?

Thanks in advance.

*This post is locked for comments

  • Suggested answer
    Syed Wajid Ali Profile Picture
    Syed Wajid Ali 25 on at
    RE: Set default parameter values

    Use Business Logic following business logic provide parameters value on both end in SSRS and AX

    [DataMethod(), AxSessionPermission(SecurityAction.Assert)]

    public static DataTable DateFromToDefaultValuesDataTable()

    {

    DataTable dateRangeTable = new DataTable();

    dateRangeTable.Columns.Add("DateFrom", typeof(DateTime));

    dateRangeTable.Columns.Add("DateTo", typeof(DateTime));

    dateRangeTable.Rows.Add(new object[] { DateTime.Today.AddDays(-7), DateTime.Today });

    return dateRangeTable;

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: AX2012R2 - Set default parameter values

    Hi, just wondering how did you set it in the build method of UIBuilder class.. hoping you can help me out thanks.

  • Dan Emreus Profile Picture
    Dan Emreus 1,162 on at
    RE: AX2012R2 - Set default parameter values

    I do not know why it did not work for you before but am glad that you found another solution that did.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: AX2012R2 - Set default parameter values

    I've written a UI Builder class that extends SrsReportDataContractUIBuilder and set the date values in the build method. This seems to work how I want, so I will stick with it.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: AX2012R2 - Set default parameter values

    Hi Adam,

    I tried setting the parameters by default in the report but AX still overrides them. If I run the report in plain old SSRS via Report Manager, with no AX intervention, the parameters are populated fine, the problem only occurs when I run the report from AX.

    Rick.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: AX2012R2 - Set default parameter values

    Hi Dan,

    I did a incremental CIL build (I always do),but this made no difference. I think it maybe a syslastvalue problem because my old values are always populated regardless of what I do. I'm not sure how to fix this problem?

    Rick.

  • adam260 Profile Picture
    adam260 1,871 on at
    RE: AX2012R2 - Set default parameter values

    you could always set up the defaults within the srrs report on the parameters themselves?

  • Suggested answer
    Dan Emreus Profile Picture
    Dan Emreus 1,162 on at
    RE: AX2012R2 - Set default parameter values

    I do not see why this should not work. Could it be a CIL- or a syslastvalue problem?

    /Dan

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: AX2012R2 - Set default parameter values

    Thanks Dan for your response.

    I've tried what you suggest already, but couldn't get it to work. I'm obviously doing something wrong. My class Declaration looks like this:

    [DataContractAttribute]

    class HSP_XXX_RickSrsContract

    implements SysOperationInitializable

    {

       TransDate startingDate;

       TransDate endingDate;

    }

    and my initialize method looks like this:

    public void initialize()

    {

       startingDate = systemDateGet()-7;

       endingDate = systemDateGet();

    }

    and my parms look like this:

    [DataMemberAttribute("endDate")]

    public TransDate parmEndDate(TransDate _endingDate = endingDate)

    {

       endingDate = _endingDate;

       return endingDate;

    }

    [DataMemberAttribute("startDate")]

    public TransDate parmStartDate(TransDate _startingDate = startingDate)

    {

       startingDate = _startingDate;

       return startingDate;

    }

    When I run the report in AX, I'm still seeing the old values in the start and end date fields, not the dates initialized above? Also, If I put a break point in the initialize method, it doesn't get hit when I run a test job I have set up?

    Thanks again,

    Rick.

  • Suggested answer
    Dan Emreus Profile Picture
    Dan Emreus 1,162 on at
    RE: AX2012R2 - Set default parameter values

    Create this method on the contract:

    public void initialize()

    {

       YourStartDate = systemDateGet() -7;

       YourEndDate  = systemDateGet();

    }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans