Take customer's name from all companies

abnainasabnainas Member Posts: 174
Dear All.
I have a NAV database that consist of 5 companies. for each company has it's own customers. The issue is that can I retrieve all the customers from all companies in one shot. #-o
Ahmad Bani Naser
Dynamics NAV Developer

Comments

  • BgestelBgestel Member Posts: 136
    try the

    CHANGECOMPANY

    command
    **********************
    ** SI ** Bert Van Gestel **
    **********************
  • abnainasabnainas Member Posts: 174
    Thanks... i use the CHANGECOMPANY function and it is worked. But it give me the customers for one company. I want all customers in all compaines.

    Best Regards
    Ahmad Bani Naser
    Dynamics NAV Developer
  • JohnConJohnCon Member Posts: 55
    Remember that after you changecompany you must then reset your filters and set the range again.
    Are you running a report or a form?
    Do you have an examle of your code?
  • abnainasabnainas Member Posts: 174
    edited 2007-07-03
    Thanks
    Ahmad Bani Naser
    Dynamics NAV Developer
  • pdjpdj Member Posts: 643
    To help one of your problems, then you should try looking at the Company table. Simply loop through it, and then you don't need to hardcode company names in your code.

    However, it seems you try to show customers from all companies in one list, is that correct?
    Then you will have to create a new table, unless you know (or is allowed to assume) that no Customer No. is used in more than one company. Then create a new table with primary key Company,"Customer No."
    Then let your code loop through the companies and for each company loop through customers and fill a temporary record variable. But if you have a lot of customers it might take quite some time. A different solution could be making the new table DataPerCompany=No and ensure it was updated when the customers are updated. That would be quite a big task, but not impossible. If you are using SQL, you could create a SQL View. However, then I still think you'll need to hardcode the companynames.

    I'll recommend not using the standard customer list form, eventhough you might get told that no customer no. is reused in multiple companies. All the functions and sub-views will be messed up when you try to do anything with a customer from a different company.

    Depending what your client is trying to gain from you help, the solution might be to mark the Customer table as DataPerCompany=No.
    Regards
    Peter
  • DenSterDenSter Member Posts: 8,305
    It's not possible to list all customers from all companies in one list. A form can only be linked to one table, and each company has its own Customer table.

    You will have to develop something to retrieve that information into a new table and display the content of that table on your form.
  • BgestelBgestel Member Posts: 136
    damn,

    and i thought i was onto something here.

    ](*,)
    **********************
    ** SI ** Bert Van Gestel **
    **********************
  • abnainasabnainas Member Posts: 174
    edited 2007-07-03
    Thanks
    Ahmad Bani Naser
    Dynamics NAV Developer
  • DenSterDenSter Member Posts: 8,305
    Something like this:
    IF Company.FINDSET THEN BEGIN
      REPEAT
        Customer.CHANGECOMPANY(Company.Name);
        IF Customer.FINDSET THEN REPEAT
          TempCustomer.INIT;
          // set all fields, use transferfields or copy or whatever else works
          TempCustomer.INSERT;
        UNTIL Customer.NEXT = 0;
      UNTIL Company.NEXT = 0;
    END;
    
    I'm writing this off hand, have not tested it.

    It looks like you should read the application designers guide and maybe even the developer training material, because it doesn't look like you understand record navigation in C/AL code yet.
  • abnainasabnainas Member Posts: 174
    Dear DenSter
    it's works ... thanks for your corroboration.

    I just wondaring if I can get customers form another database.? it's possible or not ?

    Best Regards
    Ahmad Bani Naser
    Dynamics NAV Developer
  • BgestelBgestel Member Posts: 136
    Hahaha, now you are pushing it :D

    The only way i know of to do that is by making a view on the sql server.
    **********************
    ** SI ** Bert Van Gestel **
    **********************
  • abnainasabnainas Member Posts: 174
    edited 2007-07-03
    :-$
    Ahmad Bani Naser
    Dynamics NAV Developer
  • BgestelBgestel Member Posts: 136
    I mean that you are making it harder and harder on yourself.

    And me, the joyfull person that i am, i thought i would give you the answer with a little laugh.

    So no need to search for a deaper meaning , is this a cultural issue for you or did you just not understand, i'm interested?
    **********************
    ** SI ** Bert Van Gestel **
    **********************
Sign In or Register to comment.