How to changecompany directly

wirowiro Member Posts: 92
edited 2007-07-19 in Navision Attain
If you want to change company you should go to File - Company - Open.
Any other way ? With coding perhaps ?
I only know with hyperlink but if different company navision ask for user id and password.
Thank you.

Comments

  • Captain_DX4Captain_DX4 Member Posts: 230
    You can change a company by using the CHANGECOMPANY function of a record. This only allows you to access the data in the other company for that record within code. It does not automatically change the accessible company for the user.
    Kristopher Webb
    Microsoft Dynamics NAV Developer
  • krikikriki Member, Moderator Posts: 9,112
    You can change a company by using the CHANGECOMPANY function of a record. This only allows you to access the data in the other company for that record within code. It does not automatically change the accessible company for the user.
    But be carefull, because ALL (tablerelations, records-variables in the triggers) other references to records are still in the ORIGINAL company!
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • wirowiro Member Posts: 92
    I know changecompany. But it's only open a record. record.changecompany(companyname).
    I have case one database with a lot of companies.
    Thank you.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    What is it you want to do? Maybe there are other ways?

    Please explain more.
  • DenSterDenSter Member Posts: 8,307
    There is no C/AL way to log into a company. If you realy need to do this automatically, you could use NAS. There have been a few threads about restarting NAS in a different company that may be helpful.
  • wirowiro Member Posts: 92
    Forgive my ignorance, what do you mean by threads?
    I don't understand.
    Thank you denster.
  • ara3nara3n Member Posts: 9,256
    by threads he means topics that other people were discussing. Search for it and you'll find the discussion on mibuso.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Captain_DX4Captain_DX4 Member Posts: 230
    kriki wrote:
    But be carefull, because ALL (tablerelations, records-variables in the triggers) other references to records are still in the ORIGINAL company!

    Good to know! I have been using CHANGECOMPANY primarily to get customer records from one company into another. Just as a way to relieve data-entry personnel from too much extra work. We have separate companies setup in the database that correspond to different years of an event, so registrations come in year after year and we just copy them across.
    Kristopher Webb
    Microsoft Dynamics NAV Developer
  • krikikriki Member, Moderator Posts: 9,112
    kriki wrote:
    But be carefull, because ALL (tablerelations, records-variables in the triggers) other references to records are still in the ORIGINAL company!

    Good to know! I have been using CHANGECOMPANY primarily to get customer records from one company into another. Just as a way to relieve data-entry personnel from too much extra work. We have separate companies setup in the database that correspond to different years of an event, so registrations come in year after year and we just copy them across.
    I found it out the hard way. When programming something, it didn't work for this reason, so I had to rewrite a lot.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • DenSterDenSter Member Posts: 8,307
    Just stay away from VALIDATE and you should be fine, as long as your code sets the company for ALL record variables explicitly.
  • Captain_DX4Captain_DX4 Member Posts: 230
    DenSter wrote:
    Just stay away from VALIDATE and you should be fine, as long as your code sets the company for ALL record variables explicitly.

    OOooh, is that what the issue was? I see. Well, that just makes sense. You can't VALIDATE on a table with a table relation unless the options exist, so that just makes good programming sense. *hehe* I've found the best way is to make the settings in some of the tables identical for every company, which a lot of Navision installations will do anyways (at least in my experience). Makes sense too. Payment Terms codes, for example, shouldn't be that radically different across companies in Navision, unless the client's functional companies are using radically different business rules. It just makes setup easier too.

    Cheers!
    Kristopher Webb
    Microsoft Dynamics NAV Developer
  • wirowiro Member Posts: 92
    Thank you guys.
    Can i do posting to another company from another company ? Of course not. But, any other way to make it easier...coz, i'm dealing with a lot of companies, hundreds of companies....need a lot of people and need a lot of time to post something.
  • Captain_DX4Captain_DX4 Member Posts: 230
    Essentially, no. I mean, there may be a way if you want to go through ALL the posting code and update everything to be able to post into another company, but even then I'm not sure if the CONSISTENT functionality would work.

    Far easier to just have the users go into the new company to post.

    Why so many companies?
    Kristopher Webb
    Microsoft Dynamics NAV Developer
  • krikikriki Member, Moderator Posts: 9,112
    Some trick I used once (before the NAS existed, now you might use the NAS).
    A when posting sales invoice in one company had to create a purchase invoice in another company. Not being able to use the VALIDATE-triggers in the second company, I created information in new tables that were DataPerCompany=FALSE. When someone entered a company, I checked if there were invoice to be created and if there were, I checked in the user had enough permissions to do it. If yes, I put a confirmation-box to ask him to create the invoices, and if he answered yes, I just created them.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • kishi_gkishi_g Member Posts: 162
    how can i copy record from one company to another company?? i dont want all data i want only selected records transfered to another company??
  • Captain_DX4Captain_DX4 Member Posts: 230
    kishi_g wrote:
    how can i copy record from one company to another company?? i dont want all data i want only selected records transfered to another company??

    The top of this thread explains it fairly well. You need to create two record variables for the same table:

    Var1Table1
    Var2Table1

    Then you need to invoke the CHANGECOMPANY function:

    Var2Table1.CHANGECOMPANY('XYZ');

    Then you can filter each of the variables and use them as normal:

    Var2Table1.GET...
    Var2Table1.SETRANGE...

    Copy the variable:

    Var1Table1.INIT;
    Var1Table1 := Var2Table1;
    Var1Table1.INSERT;
    Kristopher Webb
    Microsoft Dynamics NAV Developer
  • kishi_gkishi_g Member Posts: 162
    Hi Captain DX4,
    I put the code in On Push Trigger in Contact Card. when i press the command button it shows "contact nunber is already exist".


    what can I do???
  • Captain_DX4Captain_DX4 Member Posts: 230
    I think you want to establish a new record first, based on the primary key, and then only copy fields that don't overwrite the primary key fields.
    Kristopher Webb
    Microsoft Dynamics NAV Developer
Sign In or Register to comment.