Forum Discussion

bhandelman's avatar
bhandelman
New Contributor III
2 years ago

How to identify which environment a BR is running in?

I have some business rules that need to identify which environment the BR is running in. This is because they does different things in each environment. In one BR i want the process to run in Prod but not QA or Dev, in another i want to copy extract files to an external shared folder which is different for each environment.  I was thinking of using a dashboard parameter but if after a Prod to Dev/QA refresh i forget to change the value of the parameter, the BR will copy the files to the Prod external folder and i don't want that to happen. this is why i am trying to find a way to identify the environment without relying on the value in a parameter.  Any thoughts?

Have a great day!

Bill

  • You could retrieve the connection URL using,

    si.WebServerUrlUsedByClient

    & differentiate the Environment by identifying specific keywords (Dev/Stage/Prod) in it.


  • ST1's avatar
    ST1
    New Contributor III

    I need to use the environment name defined in the "Environment Name" variable in System tab, I need to use it in business rule. I need to use "FPCC_NonProd" in the business rule.

     

    Can you please suggest how can I use ?

    • JussiPukki's avatar
      JussiPukki
      New Contributor III

      At least you can find it it in the ServerConfig table in Framework database.

      				Dim sql As String = "
      					SELECT TOP 1 
      						TextValue 
      					FROM ServerConfig
      					WHERE ItemName2 = 'EnvironmentName'
      				"
      				
      				Using dbConnFW As DBConnInfo = BRApi.Database.CreateFrameworkDbConnInfo(si)
      				    Using dt As DataTable = BRAPi.Database.ExecuteSql(dbConnFW, sql, True)
      				        If Not dt Is Nothing Then
      				            BRApi.ErrorLog.LogMessage(si, dt.Rows(0).Item("TextValue"))
      				        End If
      				    End Using
      				End Using

      Not sure if there's a smarter way.

  • JussiPukki's avatar
    JussiPukki
    New Contributor III

    si.WebServerUrlUsedByClient gave an empty string when I tried using it in v8.2.1. As an alternative solution, I ended up creating a system level dashboard parameter to store this info in the framework database. Should work for us as we only copy applications between environments.

    • DanielWillis's avatar
      DanielWillis
      Valued Contributor

      Try this.

      Dim harvestFolder As String = BRAPi.Utilities.GetFileShareFolder(si, FileShareFolderTypes.BatchHarvest, Nothing)
      Dim serverName = harvestFolder.Split("\")(2)

      Just grabbed it out of some code lying around but believe it works.

  • hiren's avatar
    hiren
    New Contributor III

    You could retrieve the connection URL using,

    si.WebServerUrlUsedByClient

    & differentiate the Environment by identifying specific keywords (Dev/Stage/Prod) in it.


    • bhandelman's avatar
      bhandelman
      New Contributor III

      hiren, Thank you, that is exactly what I needed. 

  • AK's avatar
    AK
    New Contributor III

    Please see if the substitution variable |AppName| helps. This is a general substitution variable cand provides the application name. It can be used in Business rules.

    • bhandelman's avatar
      bhandelman
      New Contributor III

      Unfortunately we use the same application name for all our environments.  We are currently On-Prem.  When we refresh from Prod to Dev and QA we do not rename the Dev/QA applications.  if we did, that would work great. Any other thoughts?