Accessing realm values from functions

I would like to store strings in values. Currently stuff like the database name and an API URL. The docs say I can store a string, array, or object. The simplest way I can store a string seems to be {“name”: “dbName”}. This makes accessing it somewhat convoluted, const dbName = context.values.get(“DB”).name. Is there a more straightforward way? I was thinking that values would appear as globals or environment variables, assessable by name in realm functions.

1 Like

Hi @Stephen_Reilly :wave:

You can store the string value directly into the Realm Value rather than nested in a JSON object. When storing string values you need to make sure that you wrap the value in quotation marks like so "<VALUE>" as it needs to follow JSON syntax.

Is there a more straightforward way?

Currently the only way to access values in the function context is through the getter function

const dbName = context.values.get("DB_NAME")

I hope this helps :smiley:



Right, ok. I had tried that. What threw me was the UI strips out the quotations when you save it and gives you an error. So every time you want to modify a string value you have to reinsert them.

Yes that is correct, you have to reinsert them unfortunately.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.