Global variables

Posted by: jhl on 4 August 2017, 2:32 pm EST

  • Posted 4 August 2017, 2:32 pm EST

    Hi,

    I'm working on a invoice report where i have some inventory groups that i want to show inn the footer of the report. How can I do this? I've tried to use global variables, but since this list will change for every page, it didn't work as planned.

    Scenario:
    Lets say the first invoice is going to contain I-Group1 to I-Group3. The next invoice I-Group2.
    The first page is ok and shows groups as it should, but next page show group2, but i also shows the groups from last page. I've tried to clear the variables in "onPageEnd" but didn't help.
    If i only make the report to show one invoice it works, but that is not very effective when 100 invoices is printed.

    Does someone know how to do this? 
    PS! Working in a end user program, i only have access to script editing.
     
  • Replied 4 August 2017, 2:32 pm EST

    Thank you for your replay.

    But if i need to do this in code, is there a possible way to do that?
    An example orderline row returned from DB is:

    ID - Name - Quantity - Price - Sum - Group

    Where group is supposed to show in the footer. But only once. The same groupe can be included in multiple rows. So what i tried was to check if the group was "printed" before with the variables and when the page were at the end i wanted to clear the variables so the next page would "print" the correct groups for that invoice. But i didn't get that to work.

    Any solutions?

  • Replied 4 August 2017, 2:32 pm EST

    I would make sure the report groups are bound to the proper datafield column in the database. It sounds like you're attempting to do this in code, which can cause data to become out of sync.
  • Replied 4 August 2017, 2:32 pm EST

    ?Is the number of groups know?  Is there a limit on the number of groups?
  • Replied 4 August 2017, 2:32 pm EST

    ?

    Thank you for your replay. But i think i have to try to explain my problem better.

    Lets say the query returns the following from the database for invoice number 1 (added groupsum since last time):

    ID - Name - Quantity - Price - Sum - Group  - GroupSum
    1    ProdA          1          $10      $10   Group1       $20
    2    ProdB          2           $5       $10   Group2       $10
    3    ProdC          1          $10      $10   Group1       $20

    I now have two products wich is from Group 1 and one product from group 2. But i only want to show the group name one time if it occurs in one or more rows.

    So in the footersection i want to show the following:

    Groups:
    Group1  $20
    Group2  $10

    How can i do this?

    (remember i have only access to end user script editing and control adding)

  • Replied 4 August 2017, 2:32 pm EST

    Use a GroupHeader/GroupFooter tied to your Group field.

  • Replied 4 August 2017, 2:32 pm EST

    Here is what I am thinking.

    Load a second summarization recordset. We are not really going to bind to it, just really use it as a reference array. I know it is possible to do this via script as unbound reporting involves the passing of recordsets. In your specific case it might not be as I do not know what you have in your code that the script can access.

    The recordset would be one to ten records long and would basically consister of the the Groupname and the sum value. You could link each row to it based on the groupname to get your Sum in the detail row.  Then loop through the recordset for your footer section.

  • Replied 4 August 2017, 2:32 pm EST

    You will need code access to do what you are describing since you need more than one record set represented on the report. Also accessing controls and storing values in global variables isn't recommended since the data can become out of sync. One other option not discussed is creating a subreport based on a recordset containing summary information from your main report's database. This will take actual code to use AddNamedItem and will require the subreport object to be created outside the report at runtime. The code needed is given in the KB and in our helpfile:
    http://www.datadynamics.com/ShowPost.aspx?PostID=580
    http://www.datadynamics.com/ShowPost.aspx?PostID=491
    http://www.datadynamics.com/Help/AR2/AR2Std/HX_Chapter_7_Subreports.html
    http://www.datadynamics.com/Help/AR2/AR2Std/HX_Chapter_14_Scripting_and_XML.html
  • Replied 4 August 2017, 2:32 pm EST

    I think you could pull the connection string off whatever is your primary datasource, I assume DataControl?

    If this recordset idea doesn't work.  Another thought would be to load a subreport into the ReportFooter. You wouldn't have the GroupSums on each record, but it would match your original critiria of having them in the footer.

    As far as creating an example goes, you would be far better off asking one of the DD team as they have much more experience, and besides, it is their job [:D].
  • Replied 4 August 2017, 2:32 pm EST

    I've included the code wich i have in the script editor so you can have a look at it.
    I follow your idea, but i'm not sure if i have enough access to connection strings for DB etc. to do this. 
    Do you have time to make me an example out of what you see in this file?

    Wich DB it connects to and runs the queries against will be different depending on wich client that have logged on.
    Example: Client 1 uses SQL server catalog Client_1, and Client 2 uses catalog Client_2 etc..
    Will this make it impossible to solve my problem with only the scripteditor?

    Thank you for your help so far.

    2005/03/Code.txt
  • Replied 4 August 2017, 2:32 pm EST

    ?
     brandon wrote:
    I would make sure the report groups are bound to the proper datafield column in the database. It sounds like you're attempting to do this in code, which can cause data to become out of sync.
    test...
  • Replied 4 August 2017, 2:32 pm EST

    ?

    Yes, we can set the limit of groups to 10, but one invoice might show 1 group while another invoice will show 5 etc. But the limit is 10.
    If you can help me with this one you are a life saver Smile

Need extra support?

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

Learn More

Forum Channels