General Technical Discussions for Service

Get Involved. Join the Conversation.


    Will Lanni
    Use custom config key from json object parsed into variable...
    Topic posted August 2, 2018 by Will LanniBlue Ribbon: 750+ Points 
    43 Views, 1 Comment
    Use custom config key from json object parsed into variable name. Doesn't work in Staging


    I have a json object I am storing in the Configuration Settings as the value of a config key. This object is storing a mixture of integers (representing answer IDs), and strings of other custom configuration keys that in turn store integer values. Basically, this is a custom navigation object that stores a hierarchy of answers, some of which need to be controlled by configuration settings. I'll post an example below.

    My widget pulls in that json object and parses it into a PHP array. This works fine. I then need to recursively walk through the array and replace the configuration key name strings with their integer values.

    I can do this in the development environment using a constant() function to parse the array value of the configuration key name into its respective configuration ID, and then run getConfig() to get the value of that configuration key. However, in Staging and Production, those configuration key name constants are treated differently, and the whole thing breaks.

    I next created functions to detect which environment I'm in, so that between environments I can run different functionality to get those values. Again, I can get the development environment working, but I am having trouble figuring out what the system is doing with those constants in Staging. When I wrote the constant name out in the view.php of the widget I'm authoring, in Development it remains as a string representation, but in staging/production it is automatically converted to its respective integer ID. However, this doesn't seem to be happening in the array.

    Service Cloud
    Code Snippet:



    • Will Lanni

      Looks like in staging the value $needle is replaced with the ID surrounded by paranthesis, e.g. in my replaceConfigKeys() function:

      $needle = "CUSTOM_CFG_KEY_NAME"; // parses to (100008)

      $item = getConfig($needle); 

      prints out to

      $item = getConfig((100008));

      however, an eval doesn't seem to work either:

      eval("$item = getConfig$needle;"); // returns null