Open Forum

Expand all | Collapse all

AL Code - get database indicator?

  • 1.  AL Code - get database indicator?

    GOLD CONTRIBUTOR
    Posted Sep 24, 2020 01:22 AM

    We have a test and dev copy of our database and I want to change the vendor and customer email addresses to avoid any possible mistakes of invoices being sent out of a test/dev to a live email address.

    To do this I'm writing a report to loop through all companies and for each company loop through each customer and vendor and changing the email contact info to add a suffix so it would bounce.

    I want to make sure this never gets run in prod, so I could build it as a separate extension or leave it in my main extension and if I did that, I was hoping to get the system indicator text and to check for "prod" and exit out of the code if it ever gets attempted to run on a the prod database.

    CompanyInformation has the System Indicator which I've set to Company + Database for all my companies, but I can't figure out how to get the live value of this in a given company in AL so I could check to see which database the code is running in.

    What's the best/recommended way to solve this?

    Thank you



    ------------------------------
    Benji Jasik
    Generate Capital
    ------------------------------
    Academy - Online Interactive Learning from Experts


  • 2.  RE: AL Code - get database indicator?

    NAVUG ALL STAR
    Posted Sep 24, 2020 08:47 AM
    Are the test and prod systems in different databases?  You might be able use the database name to differentiate between test and prod.

    Another approach to all of this is to use RapidStart to export out your customers and vendors, update the email addresses in Excel with Find and Replace and then use rapid Start to import the changes back into the database.


    ------------------------------
    Lewis Rosenberg
    IT Manager
    Mars Fishcare
    Chalfont PA
    www.apifishcare.com
    ------------------------------------------------------------------------
    BCUG/NAVUG All-Star
    BCUG/NAVUG Board of Advisors, Chairperson
    BCUG/NAVUG Programming Committee

    Twitter: @RosenbergL
    LinkedIn: https://www.linkedin.com/in/rosenbergl
    ------------------------------------------------------------------------

    NAVUG/D365BC-Community Summit:
    https://www.dynamiccommunities.com/events/community-summit-north-america/
    October 7-9, 2020
    ------------------------------

    Academy - Online Interactive Learning from Experts


  • 3.  RE: AL Code - get database indicator?

    GOLD CONTRIBUTOR
    Posted Sep 24, 2020 10:42 AM
    Yes they are in different databases but how do I get the database name in AL code?

    ------------------------------
    Benji Jasik
    Generate Capital
    ------------------------------

    Academy - Online Interactive Learning from Experts


  • 4.  RE: AL Code - get database indicator?

    NAVUG ALL STAR
    Posted Sep 24, 2020 10:53 AM
    I don't code that much, but I recall several years ago I wrote something where I was reading data from the same table in two different databases (using C/AL).  I think for my GET command, I somehow had to specify database_name + table_name.

    I'm sure there are some developers on here that can help with that.

    ------------------------------
    Lewis Rosenberg
    IT Manager
    Mars Fishcare
    Chalfont PA
    www.apifishcare.com
    ------------------------------------------------------------------------
    BCUG/NAVUG All-Star
    BCUG/NAVUG Board of Advisors, Chairperson
    BCUG/NAVUG Programming Committee

    Twitter: @RosenbergL
    LinkedIn: https://www.linkedin.com/in/rosenbergl
    ------------------------------------------------------------------------

    NAVUG/D365BC-Community Summit:
    https://www.dynamiccommunities.com/events/community-summit-north-america/
    October 7-9, 2020
    ------------------------------

    Academy - Online Interactive Learning from Experts


  • 5.  RE: AL Code - get database indicator?

    Posted Sep 25, 2020 07:38 AM
    I took the approach Lewis suggested by having a check against the database name. We are on NAV 2017 and I have not dabbled much in AL so I don't know how well this will translate over to AL but it may get you down the right path. I developed a similar report to convert a restored database into a test database and include the code below in the OnInitReport section. I am sure there is more than one way to skin this particular cat but this worked for me. It basically checks to see what database your session is connected to and checks it against the hardcoded test database name to make sure it matches and if not throws an error. Hope this helps.

    Note: ActiveSession is table 2000000110 Active Session

    DatabaseName := 'your database name';

    IF NOT CONFIRM('Are you sure you want to convert this to a TEST environment?') THEN
      ERROR('Cancelled');
    ActiveSession.GET(SERVICEINSTANCEID,SESSIONID);
    IF ActiveSession."Database Name" <> DatabaseName THEN
      ERROR('This is not the test database ' + DatabaseName + '!!!');

    ------------------------------
    Jonathan Kleist
    NAV Administrator
    Gustavo Preston
    Chelmsford
    ------------------------------

    Academy - Online Interactive Learning from Experts


  • 6.  RE: AL Code - get database indicator?

    GOLD CONTRIBUTOR
    Posted Sep 25, 2020 08:09 AM

    I've seen this mentioned before, using the Active Session table;

     

    ActiveSession.SETRANGE("Session ID",SESSIONID);

    ActiveSession.FINDFIRST;

    MESSAGE(ActiveSession."Database Name");

    John Bellinger
    Business Systems & Applications Manager
    Office: 952-392-3912 | Cell: 612-719-0289
    Activar, Inc.
    9700 Newton Ave. S. | Bloomington, MN 55431
    jbellinger@activar.com | www.activar.com




    Academy - Online Interactive Learning from Experts


If you've found this thread useful, dive deeper into User Group community content by role