ask for a parameter

Posted by: darin on 2 June 2022, 5:34 am EST

  • Posted 2 June 2022, 5:34 am EST

    We have upgraded from AR11 to AR16.
    We have customers that in their RPX file they have it setup to ask for a parameter. For example, on a form it asks for Country and then it will display on the form.
    Now, with AR16, it doesn't ask for the parameter.

    I even tried to setup a new RPX, added a Parameter1 to ask, and when running that RPX it does not ask for the parameter.

    How do we get the RPX to ask for the parameter?

    Attached is the RPX/ZIP file.rARCustomerUSER.zip
  • Replied 2 June 2022, 11:02 pm EST

    Any word on this? This is the first customer we have upgraded to the newer version of AR and they are having this issue. And we have 300+ other customers to upgrade.

    I did some more testing this morning and selecting PREVIEW from the designer does ask for the parameter, but running it from our application does not.

    on report
    ShowParameterUI=true
    on the parameter itself
    PromptUser=true

    i followed the PDF documentation and it says all that is needed is a parameter, and the two options above set to true and it will ask.
  • Replied 9 June 2022, 5:59 am EST

    Hello,

    We apologize for the delay in response, we are able to replicate the issue at our end and have forwarded the same to the concerned team for further investigation. We will inform you, once we have an update on the same.

    Regards
    Dushyant Sharma
  • Replied 12 June 2022, 4:28 pm EST

    Hello,

    We have an update on the above issue, could you please try using the following code snippet:


    GrapeCity.ActiveReports.SectionReport rpt = new GrapeCity.ActiveReports.SectionReport();
    rpt.LoadLayout(System.Xml.XmlReader.Create("./sampleRpt1.rpx"));
    viewer1.LoadDocument(rpt);


    You may also refer to the sample implementing the same below.

    ReportViewer_.zip

    Regards
    Dushyant Sharma
  • Replied 12 June 2022, 11:21 pm EST

    Thank you. I see that your sample does ask for the parameter (and then fails due to a SQL error).
    Your code is different than ours for loading the report onto the viewer.
    I have modified your code to be the same as ours, and yours fails (it doesn't ask for the parameter and fails on the rpt.run line with an error: "Exception has been thrown by the target of an invocation").

    GrapeCity.ActiveReports.SectionReport rpt = new GrapeCity.ActiveReports.SectionReport();
    rpt.LoadLayout(System.Xml.XmlReader.Create("./sampleRpt1.rpx"));
    //viewer1.LoadDocument(rpt);
    rpt.Run(false);
    viewer1.Document = rpt.Document;

    I modified our code to load and run the ways yours does using the view.loaddocument(rpt) and we receive the generic error "Object reference not set to an instance of an object".

    In addition, i see your code is using AR 16.1.1.0 and ours is using 16.0.0.0 - not sure if this is causing any type of issue - i don't think so seeing as when i change your code it fails also.

    Our psuedo code is:
    rpt.userdata=sqlconnectionstring
    rpt.datasource=sqldatareader (with the data already loaded in it from the SQL select statement)
    rpt.run(False)
    viewer.document=rpt.document

    Thanks for any additional help you can provied.
  • Replied 13 June 2022, 9:43 pm EST

    Hello,

    Please try removing the run() method from the above code snippet as its starts the report processing in blocked mode and would prevent the parameter prompt in the viewer.

    Furthermore, If you wish to assign the data source at runtime, please try using the SectionReport events to do the same.

    https://www.grapecity.com/activereportsnet/docs/latest/online/ar-wlk-runtime-datasources.html

    You can refer to our unbound SectionReport sample, using the below link:
    https://www.grapecity.com/activereportsnet/docs/latest/online/unbound-array-sample.html

    Sample: https://github.com/activereports/Samples16/tree/main/DataBinding/Section/UnboundData/C%23

    Regards
    Dushyant Sharma
  • Replied 13 June 2022, 10:18 pm EST

    I will try your suggestions - but the rpt.run used to ask for the parameter on previous versions of AR.
  • Replied 13 June 2022, 10:44 pm EST

    Just so i 100% understand what you are saying:

    The rpt.Run actually runs the report, but doesn't do report logic built into the script, such as asking for the parameter.

    The only way to have a report 100% driven by runtime (connection string and SQL dataset) would be to change the way the report is generated and have the connection string and SQL dataset in the actual script itself and not use the rpt.run. The reason this is difficult is all of our standard RPX files are built into DLL's that are in our program, so the script is in the program. The same holds true for the SQL statement used to drive the report - anytime a report is run the parameters (and thus the SQL statement) can be different, even for the same user same connectionstring. This is why we are using the rpt.run - so it is driven from within the program and pushing the dataset to the report. How can i give a dataset to the report without using the rpt.RUN?

    This change occurred sometime between AR11 and AR16. I could not find anything on https://www.grapecity.com/activereportsnet/docs/latest/online/breaking-changes.html that explain how this logic changed. Can you shed some light on this please.
  • Replied 20 June 2022, 4:48 am EST

    Any other information you can give me about how to do what we are doing and have the parameters work?
  • Replied 22 June 2022, 2:28 pm EST

    Hello,

    Calling the rpt.run() method causes the report to start processing in blocked mode and render the report independently of the viewer. Thus, to ensure that we have the prompt on running the form, please try removing the call for the run() method,

    Furthermore, If you don't wish to use the report events to set the dataSource, you can try using the report.DataSource property and assigning the required data within it accordingly.

    Regarding the error "Object reference not set to an instance of an object", could you try please try sharing a stripped-down sample depicting the issue or update the below sample. so that we may investigate and reply accordingly.

    ActiveReports Demo Application.zip

    Regards
    Dushyant Sharma
  • Replied 18 July 2022, 1:14 am EST

    I am back to working on this, since the parameter was one of the 2 issues i had with AR16.

    Using your sample, it pulls up the report in the viewer and asking for the parameters. Now, i am trying to modify it to print directly to the printer with the printer pre-assigned.

    report.Document.Printer.PrinterName = "D570";
    report.Docuemtn.Printer.PrinterSettings.COpies=2;
    viewer1.LoadDocument(report);
    viewer1.Print(false);

    the PRINT line receives an error saying you can't do this until the report is completely loaded. How do we know the report is loaded before calling the print command.

    Our application has pre-assigned printers for reports everywhere, that is why we are currently doing the report.Run() and then report.Document.Print. The only time we load the "viewer" is when the report is being printed to the screen, otherwise everything is in the background.

    Thanks.
  • Replied 18 July 2022, 8:08 pm EST

    Hello,

    To ensure that the report has loaded completely, you can try using LoadCompleted event of the viewer and try calling the print() method in the same as follows:


    private void viewer1_LoadCompleted(object sender, EventArgs e)
    {
    report.Document.Printer.PrinterName = "D570";
    report.Document.Printer.PrinterSettings.Copies = 2;
    viewer1.Print(false);
    }


    Please refer to the updated sample below.
    Sample.zip

    Regards
    Dushyant Sharma

  • Replied 18 July 2022, 11:07 pm EST

    So the only way to do this is to load the viewer? We only load the viewer when the user prints it to the screen.
  • Replied 21 July 2022, 2:37 pm EST

    Hello,

    Yes, If you wish to allow the user to select the parameters, proceeding which you wish to generate the report based on the user selection, and then print/export the same, you would have to use the viewer as explained in the above solution.

    Regards
    Dushyant Sharma
  • Replied 21 July 2022, 9:22 pm EST

    I guess i don't understand the purpose of this:

    Calling the rpt.run() method causes the report to start processing in blocked mode and render the report independently of the viewer.

    Why won't rpt.run run the report for real, asking parameter as it was in previous versions? I don't understand why i have to load a report, then load the report into a viewer, to then print it.
  • Replied 24 July 2022, 9:28 pm EST

    Hello,

    We have requested clarification on the above issue from the concerned team and will update you on the same at the earliest.

    However, as a workaround, If you don't wish to load the viewer to set the parameters, you can also use the Parameters property which represents the collection of report parameters to set the same via code, and then try running the run() method as follows:


    report.LoadLayout(System.Xml.XmlReader.Create("./Reports/sampleRpt.rpx"));
    report.Parameters["InputParameter"].Value = "Test Value";
    report.Run();


    Updated Sample: Sample_.zip

    Regards
    Dushyant Sharma
  • Replied 24 July 2022, 10:46 pm EST

    thank you for the sample.

    is there a way to read the rpx before hand to know if there is a parameter and to get all the values that are needed? I know we have some customers that have 3 parameters on reports, some with one, some with 2, etc.
  • Replied 27 July 2022, 1:52 pm EST

    Hello,

    We have an update on the above issue, it seems like the above-described behavior as shown in ActiveReports 11 was removed in ActiveReports 15 onwards. Thus, to resolve the same as, we would recommend using a custom dialog, For Example:


    SectionReport report=new SectionReport();
    report.LoadLayout(XmlReader.Create(@"./reportParameterTestv11.rpx"));

    foreach (GrapeCity.ActiveReports.SectionReportModel.Parameter p in report.Parameters)
    {
    p.Value = Microsoft.VisualBasic.Interaction.InputBox("Enter the parameter value",
    p.Prompt,
    "123",
    500,
    500);
    }

    report.Run();
    viewer.LoadDocument(report.Document);


    Regards
    Dushyant Sharma
  • Replied 27 July 2022, 1:52 pm EST

    Hello,

    We have an update on the above issue, it seems like the above-described behavior as shown in ActiveReports 11 was removed in ActiveReports 15 onwards. Thus, to resolve the same as, we would recommend using a custom dialog, For Example:


    SectionReport report=new SectionReport();
    report.LoadLayout(XmlReader.Create(@"./reportParameterTestv11.rpx"));

    foreach (GrapeCity.ActiveReports.SectionReportModel.Parameter p in report.Parameters)
    {
    p.Value = Microsoft.VisualBasic.Interaction.InputBox("Enter the parameter value",
    p.Prompt,
    "123",
    500,
    500);
    }

    report.Run();
    viewer.LoadDocument(report.Document);


    Regards
    Dushyant Sharma
  • Replied 27 July 2022, 11:14 pm EST

    Thank you. That worked as anticipated. I am doing some more testing with AR16 to confirm I don't see any other issues.

    Thank you for your help.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels