Simple report & CHANGECOMPANY function

dulamandulaman Member Posts: 73
Hi all,

This should be a very simple one -- hope!

I'm trying to create a report where I get the all four companies that are in my database, and get a list of all the customers for that company.

I mean something like this:

Company One
Customer #1
Customer #2
Company Two
Customer #3
Customer #4
Company Three
Customer #5
Customer #6
Company Four
Customer #7
Customer #8

I'm trying it by making a loop with the Company table, then I put the Customer table into the loop and insert a CHANGECOMPANY function in the Customer section, but all I get is always the same customers, like this:

Company One
Customer #1
Customer #2
Company Two
Customer #1
Customer #2
Company Three
Customer #1
Customer #2
Company Four
Customer #1
Customer #2

What #&@## am I doing wrong??? ](*,)
-- dulaman
"I don't want to believe. I want to know." (Carl Sagan)

Answers

  • andreofandreof Member Posts: 133
    Have you tried something like this:


    Integer
    Customer


    Integer OnpreDataItem
    SETRANGE(Number,1,4);


    Customer OnPreDataItem

    CASE Integer.Number OF
    1: Customer.ChangeCompany(Company1);
    2: Customer.ChangeCompany(Company2);
    3: Customer.ChangeCompany(Company3);
    4: Customer.ChangeCompany(Company4);
    END;


    Hope this helps

    Regards
    Andre Fidalgo
    My world: Dynamics NAV,SQL and .NET

    CEO at Solving Dynamics
    http://www.solvingdynamics.com
  • dulamandulaman Member Posts: 73
    Thanks, andreof, but I'm getting the same result than before, i.e.

    -->Company One:
    Customer #1
    Customer #2
    -->Company Two:
    Customer #1
    Customer #2
    -->Company Three:
    Customer #1
    Customer #2
    -->Company Four:
    Customer #1
    Customer #2

    It really doesn't matter which table I indent because I always get the same results, as if the CHANGECOMPANY function was not working by some reason.
    -- dulaman
    "I don't want to believe. I want to know." (Carl Sagan)
  • andreofandreof Member Posts: 133
    I've just tried my solution and it works.

    Dont forget to indent the Customer Table.

    Integer
    Customer

    And are you sure that the other companies have different information?


    Sorry out of ideas
    Andre Fidalgo
    My world: Dynamics NAV,SQL and .NET

    CEO at Solving Dynamics
    http://www.solvingdynamics.com
  • dulamandulaman Member Posts: 73
    No deal, I'm driving crazy!! ](*,) ](*,) ](*,)
    OK, gonna explain my full plan. Maybe I'm leaving some important hint.

    I want a report where I get the names of the four companies, and the names and balances of each customer, filtering the Customer table with a WHERE(Balance (LCY)=FILTER(>0)) sentence. The Customer table is NOT a data-per-company one. It's common for all four companies. But transactions are of course dpc.

    The perfect display would be:
      Company One: Customer 1 ... Balance in Euro Customer 2 ... Balance in Euro Company Two: Customer 3 ... Balance in Euro Customer 4 ... Balance in Euro Customer 5 ... Balance in Euro
    And so on.

    But I only can get the Customer names and balances for the first company (that is, the current one). If I change manually the company (Ctrl+O), I can see different customers and balances, so info IS different for each company.

    I guess I'm missing something very important but I can't find out what the heck is!!
    -- dulaman
    "I don't want to believe. I want to know." (Carl Sagan)
  • AlbertvhAlbertvh Member Posts: 516
    Hi

    Perhaps your should CHANGECOMPANY for the Cust. Ledger Entry and Cust. Detailed Ledger Entry tables :idea:
  • DduranDduran Member Posts: 22
    Hi,

    one solution is use a record varible of the customer table and use an integer dataitem like this

    company
    Integer

    on then onafergetrecord trigger of the Company dataitem, set the range ann get the recordcount. Use this count to set the interval of the integer dataitem.

    on then on predataitem use the customer.changecompany instrucction

    yoh should use the changecompany instrucction for the cust ledger entry record too.

    Regard

    David
  • bthorbthor Member Posts: 16
    Calcfiels do not work after you have done change company. You will have to do some programing. Somthing like:
    DetailedCustLedgEntry.SETCURRENTKEY("Customer No.","Initial Entry Due Date","Posting Date","Currency Code");
      DetailedCustLedgEntry.CHANGECOMPANY(Company.Name);
      DetailedCustLedgEntry.SETRANGE("Customer No.",Customer."No.");
      IF Customer.GETFILTER("Date Filter") <> '' THEN BEGIN
        DetailedCustLedgEntry.setfilter("Initial Entry Due Date",Customer.GETFILTER("Date Filter"));
        DetailedCustLedgEntry.setfilter("Posting Date",'..%1',Customer.GETRANGEMAX("Date Filter"));
      END;
    
      IF Customer.GETFILTER("Global Dimension 1 Filter") <> '' THEN
        DetailedCustLedgEntry.setfilter("Initial Entry Global Dim. 1",Customer.getfilter("Global Dimension 1 Filter"));
    
      if Customer.getfilter("Global Dimension 2 Filter") <> '' then
        DetailedCustLedgEntry.setfilter("Initial Entry Global Dim. 2",Customer.getfilter("Global Dimension 2 Filter"));
    
      if Customer.getfilter("Currency Filter") <> '' then
        DetailedCustLedgEntry.setfilter("Currency Code",Customer.getfilter("Currency Filter"));
    
      DetailedCustLedgEntry.CALCSUMS(Amount);
    
  • dulamandulaman Member Posts: 73
    OK, the answer was not so simple as I hoped!

    I am still stuck with this issue, but thank you guys for trying so hard.

    Gonna study it in depth -- I promise you a solution. :-k
    -- dulaman
    "I don't want to believe. I want to know." (Carl Sagan)
  • AlbertvhAlbertvh Member Posts: 516
    Hi

    This is coding that I have used
      IF CompanyLoc.FIND('-') THEN
        REPEAT
          CustLoc.CHANGECOMPANY(CompanyLoc.Name);
          CustLedgEntryLoc.CHANGECOMPANY(CompanyLoc.Name);
          IF CustLoc.FIND('-') THEN
            REPEAT
              CustLoc.CALCFIELDS("Balance Due (LCY)");
              CustCon."Customer No." := CustLoc."No.";
              CustCon."Company Name" := CompanyLoc.Name;
              CustCon."Customer Name" := CustLoc.Name;
              CustCon.Balance := CustLoc."Balance Due (LCY)";
              CustCon.INSERT;
              ConsolBal."Customer No." := CustLoc."No.";
              ConsolBal."Company Name" := CompanyLoc.Name;
              ConsolBal."Customer Name" := CustLoc.Name;
              ConsolBal.Balance := CustLoc."Balance Due (LCY)";
              ConsolBal.INSERT;
              ConsolCust."Customer No." := CustLoc."No.";
              ConsolCust."Customer Name" := CustLoc.Name;
              ConsolCust."Date Last Created" := WORKDATE;
              IF NOT ConsolCust.INSERT THEN;
            UNTIL CustLoc.NEXT = 0;
          ProcessNo := 0;
      UNTIL CompanyLoc.NEXT = 0;
    

    I am inserting records into other tables but the CALCFIELDS works for each company that I access. :P
  • dulamandulaman Member Posts: 73
    OK, the expert guys don't shoot at me! :) My solution IS very simple, I know, but that's what I was looking for. Maybe I had to change my mind once or twice :whistle: but here it is my solution -- just in case some newbie like me needs it:

    DataItems:
    Company
    Cust. Ledger Entry (Indented 1)

    Cust. Ledger Entry Properties:
    DataItemTableView: SORTING(Customer No.) ORDER(Ascending) WHERE(Amount=FILTER(>0))
    GroupTotalFields: Customer No.

    In Cust. Ledger Entry - OnPreDataItem:

    CurrReport.CREATETOTALS(Amount);
    CHANGECOMPANY(Company.Name);

    In Sections create the following:
    - Company Header (just for title)
    - Company Body
    - Cust. Ledger Entry GroupFooter, and
    - Cust. Ledger Entry Footer.

    I just can assume now what was failing before: I was using a Record Variable in the CHANGECOMPANY sentence. When I removed it, everything went right. Know why? #-o
    -- dulaman
    "I don't want to believe. I want to know." (Carl Sagan)
  • dulamandulaman Member Posts: 73
    Dunno if I'm filling this topic with a lot of newbie garbage, but I should say that I saved my day when I modified Report 109 by adding a new DataItem between Customer and Cust. Ledger Entry -- and inserting the CHANGECOMPANY sentence only in the Cust. Ledger Entry section!

    So simple like that. :mrgreen:
    -- dulaman
    "I don't want to believe. I want to know." (Carl Sagan)
Sign In or Register to comment.