TypeError: $db.getAll is not a function

Hello all,

I am updating a client’s application from 2.2 to 2.3, but I am having an issue using the $db.get method. The current function is a simple get call:

exports.getDataStorage = function(key) {
    let response = $db.get(key);
    return response;
}

But I am receiving the following error:

TypeError: $db.getAll is not a function at exports.getDataStorage

I have logged the response from the function call and it prints the following:

{ state: [Function: state], always: [Function: always], then: [Function: then], promise: [Function: promise], pipe: [Function: then], done: [Function: add], fail: [Function: add], progress: [Function: add] }

I am not sure where to start troubleshooting this issue because the error is saying $db.getAll, but the actual function call is $db.get. I have confirmed that my keys are not null values. Is there any documentation on how to update these calls to 2.3? Or is there something wrong with my current syntax?

Thank you for taking the time to review my post, and please let me know if there is any additional information I can provide.

Hey @Jose_Escobar,
The Key-Value storage functions are the same irrespective of platform version 2.2 or 2.3.

You can refer the KV store docs. The method looks good. However getAll is a function from Entity storage, can you confirm if you are using key-value store? And also share your manifest.json?

I can confirm that key-value-storage is being used. Below is my manifest, and under that I have also provided additional functions that use $db within the app. There are many functions that reference this getDataStorage and all or them are stopping with an error at this point.

{
  "platform-version": "2.3",
  "product": {
    "freshservice": {
      "location": {
        "ticket_sidebar": {
            "url": "sftemplate.html",
            "icon": "styles/images/salesforce.svg"
        }
    },
      "events": {
        "onAppInstall": {
          "handler": "onAppInstallCallback"
        },
        "onAppUninstall": {
          "handler": "onAppUninstallCallback"
        },
        "onExternalEvent": {
          "handler": "onExternalEventHandler"
        },
        "onScheduledEvent": {
          "handler": "onScheduledEventHandler"
        },
        "onTicketCreate": {
          "handler": "onTicketCreateCallback"
        }
      },
      "functions": {
        "onExternalEventHandler": {
          "timeout": 15
        }, 
        "setRecurringSchedule": {
          "timeout": 15
        },
        "iparamInstall": {
          "timeout": 15
        },
        "CreateCaseSMI": {
          "timeout": 15
        },
        "GetCaseDetails": {
          "timeout": 15
        }
      },
      "requests":{
        "salesforcePostMethod": {},
        "salesforceDeleteMethod": {},
        "salesforceGetMethod":{},
        "fsPostMethod":{},
        "fsGetMethod":{},
        "fsGetMethodIparams":{},
        "fsPutMethod":{},
        "fsDeleteMethod":{},
        "postEmail":{},
        "sfContainerPostMethod":{},
        "sfGetMethod":{}
      }
    }
  },
  "dependencies": {
    "axios": "0.21.0",
    "base-64": "0.1.0",
    "lodash": "4.17.15"
  },
  "engines": {
    "node": "18.12.0",
    "fdk": "9.0.8"
  }
}

Additional functions that us $db:

const accountApiURL = () => `<%= iparam.fdurl %>/api/v2/`;
var base64 = require("base-64");
var axios = require('axios');

exports.setDataStorage = async function(key, value) {
    let data= await $db.set(key, value);
     return data
}

exports.getDataStorage = function(key) {
    let response = $db.get(key);
    return response;
}
exports.appendFailureStorage = function(key, value) {
    return $db.update(key, "append", value)
}
exports.updateDataStorage = function(key, valueKey) {
    let obj = {};
    obj[valueKey] = 1
    return $db.update(key, "increment", obj)
}
exports.appendDataStorage = function(key, value, fstaskId) {
    let obj = {};
    obj["caseids"] = [value];
    if (fstaskId) {
        obj["taskids"] = [fstaskId];
    }
    return $db.update(key, "append", obj)
}

Thanks for sharing this @Jose_Escobar

I believe the server.js file you shared is a snippet of your code. Are these functions - setDataStorage, getDataStorage something that your SMIs or event handlers invoke to operate with KV Store?

Is the error only with $db.get() or other KV methods too? These functions would return a promise so please use async - await while invoking and retrieving the response.

This is something that we don’t support with respect to iparam substitution inside server.js.