Change Company in Code

[Mike_B][Mike_B] Member Posts: 15
We have 40 companies in the database and adding all the time. Is it possible to write a report to go through each company and change the posting date (From and To) by running a single report?

I have written some code but the draw back is that I have to hard code to Company Name? Is there a way to do it without hard coding the Company Names?


"General Ledger Setup".CHANGECOMPANY('CRONUS UK Ltd.');
VALIDATE("Allow Posting From",vAllowPostinFrom);
VALIDATE("Allow Posting To","vAllow PostingTo");
MODIFY;

"General Ledger Setup".CHANGECOMPANY('CRONUS UK Ltd 2');
VALIDATE("Allow Posting From",vAllowPostinFrom);
VALIDATE("Allow Posting To","vAllow PostingTo");
MODIFY;

Regards

Mike

Answers

  • tihomirjurtihomirjur Member Posts: 21
    Hey Mike.
    There is a way. System table called Company exists and it only consists of field Name in which it stores name of company. To see how it looks like create a new form with table Company and make a list and do a preview.
    Hope it helps!
  • garakgarak Member Posts: 3,263
    U can use the table COMPANY.

    So, make a loop:
    Company.findset;
    repeat
      GLSetup.CHANGECOMPANY(Company.Name);
      GLSetup.VALIDATE("Allow Posting From",vAllowPostinFrom);
      GLSetup.VALIDATE("Allow Posting To","vAllow PostingTo");
      GLSetup.MODIFY;
    until Company.next = 0;
    

    But be carefull with validates if you use changecompany. If in the onvalidate trigger is also code that change a other table, these records in the other table will be changed on the company from where the report is running.

    Regards
    Do you make it right, it works too!
  • [Mike_B][Mike_B] Member Posts: 15
    Thanks Garak

    Works really well :D
  • DenSterDenSter Member Posts: 8,305
    garak wrote:
    Company.findset;
    repeat
      GLSetup.CHANGECOMPANY(Company.Name);
      GLSetup.VALIDATE("Allow Posting From",vAllowPostinFrom);
    
    Are you crazy? NEVER do VALIDATE when you do CHANGECOMPANY. NEVER EVER do VALIDATE when doing CHANGECOMPANY! I would like to repeat this in really big letters, but even I think that is annoying :mrgreen:

    Just assign those values, and if you need to run any of the validation logic, then you recreate that in your report. If there is no code in OnValidate of those fields, then nothing is lost. If there IS code in there, then all it takes to screw up this process is for someone to put in logic that uses a record variable.

    DO.... NOT.... USE.... VALIDATE.... WHEN.... USING.... CHANGECOMPANY!!!
    There, did it anyway :whistle:
  • [Mike_B][Mike_B] Member Posts: 15
    I have taken all advice and removed the Validates.
  • garakgarak Member Posts: 3,263
    @Daniel: For this case i wrote:
    But be carefull with validates if you use changecompany. If in the onvalidate trigger is also code which change a other table, these records in the other table will be changed in the company from where the report is running.

    The source was only copy&paste (forgotten to remove the validate, thats right).
    Do you make it right, it works too!
Sign In or Register to comment.