Add/update elements of an object

I have an Object variable where its values come from a database query. How to add/update elements to this variable in later steps? Thanks.

Using PHP server model

{
	"user" : 
	{
		"id" : 1,
		"group_id" : 3,
		"username" : "Guest"
	}
}

You should not manipulate the responses of server actions.
What is the objective here? Maybe there is a better way to do that.

Some elements won’t be in the database so I would like to manipulate the variable by adding/modifying elements like a PHP array in later Set Value steps.

29478

If you want to do this on server side, you can use repeat.
Repeat the query, and select the columns from query in the repeat step’s output. Then, inside the repeat, set your “set values” with output enabled. The output you will get would be an array with each object having the columns from query as well as from the set value steps.

2 Likes

I have a Settings table with 2 columns (setting, value) and rows for the different settings.

setting1 value1
setting2 value2
setting3 value3

Is it possible to query the Settings table and combine them into one object variable? If yes, how?

settings = [{“setting1”:value1,“setting2”:value2,“setting3”:value3}]

Getting the data in this format is a bit tricky.
What are you trying to achieve with this? Maybe there is a better way to do this.

Do one query to store/simulate into a PHP associate array in Globals vs. individual variables.

settings[‘setting1’] = value1
settings[‘setting2’] = value2
settings[‘setting3’] = value3

Variables/Queries you create in ServerActions/Globals are just JSON objects. They are not associated with the server model from what I know.

I don’t see any way to get what you want without a custom server-side formatter.
But, I can suggest you something that will bring you close to it.
Say your query that gets the data is query1 with columns setting & value, as you informed earlier.
query1.groupBy('setting') should return you a JSON object with key-value pairs of unique setting column values as key and an array as value, which basically contains the complete row.

{"setting1":[{"setting": "setting1", "value": "value1"}],
{"setting2":[{"setting": "setting2", "value": "value2"}]

If you have multiple rows in query with same setting text… it will look something like:

{"setting1":[{"setting": "setting1", "value": "value1"}, {"setting": "setting1", "value": "value2"}]

So this is where it kind of fails.
But if you have a single value always… such that setting field is unique, you can retrieve values later with:

varSettings //name of SetValue step
query1.groupBy('setting') //value of SetValue step
varSettings.settings1[0].value //fetching settings1
varSettings.settings2[0].value //fetching settings2
1 Like