Set Data Store Value/Array from query in Server Connect

I have set-up and used Data Store which works well as follows


The Data Store is populated as follows when clicking on a series of Radio Buttons

I have the resultant data displayed on the page as this


My issue is that I want to be able to populate this Data Store from a database query on opening the page. I can’t find a way to do this.

If I can’t do this with Data Store, can I do it with Session Variable/Array?

This is my initial attempt at populating a Variable/Array but obviously doesn’t give me the result that I am looking for as shown above in the Data Store example.

Can you please explain what’s the idea behind all of this? What are you trying to achieve and why do you need to copy some (which exactly?) database records into a data store?

Not easy to explain. I need to think carefully on this, perhaps do a quick video. I’ll come back to you on this.

In simple terms…

  • click on a series of radio button (up to 30 or so radio button groups).
  • the line number, button value and name are written to Data Store.
  • written back to screen here as name x value.
  • only written back to screen here so you can see it works.
  • the idea is that this is then written to DB on Save.


  • the screen below shows items checked, populated from DB.
  • also populates the Specialist List and Specialist List Ref from DB.
  • all this is stored in two DB fields Specialist List and Specialist List Ref as comma separated lists.

  • If I click on line 31 as shown in the screenshot below, the data is added to the end of the two input fields.
  • This is done by populating the Data Store variables, which in-turn then populates these fields.

  • If I were to click on the ‘0’ [zero] on line 31 then this would remove the added data from the input fields.
  • I can delete this because it is in the Data Store using ‘remove’.

BUT, I can’t do that with the other line items because they are not in the Data Store.

Complicated. Hope that makes sense. If not I can do a video in the morning, or simply give you access.


I’m sorry I don’t understand what exactly are you trying to do there and I can’t understand the need to copy some database values into a data store and which of all records should be copied and how should they be stored…
Are you even sure your workflow/idea is correct?

Do you just want to store some checkbox values in some other input? I really don’t get how is that related with data store at all…

I knew this would not be easy. I will try to give a simple overview of what I am trying to achieve in the morning. Cheers.

Hi there folks…

@Teodor, I know that this is something I will be wanting to do to in the coming weeks… and sometimes it can be quite difficult to explain our use case.

Can you please just to give us a simple example of how we can read data from the database into the Data Store?

Many thanks,

I believe your query only returns a single result, then it is easier to use a single record query. The step will then return the record as an object.

Now you don’t need the repeat1 step and can set the values sd_id and sd_name directly.

After that create a repeat with the expression {{sd_id}}.

in the repeat you set following values for you output:
name: sd_id, value: {{$value.split('_')[0]}}.
name: sd_value, value: {{$value.split('_')[1]}}.
name: sd_name, value: {{sd_name[$index]}}.

Now the repeat should output the array needed as needed in your local datastore.

App is looking great, @UKRiggers!

1 Like

I have a serverconnect that loads the data from database and then use a multi-form with hidden values to write the records back into the data store. Probably not the best code in the world but it worked for me.

<form is="dmx-serverconnect-form" id="scformLoadQuote" method="post" dmx-generator="bootstrap4" dmx-form-type="horizontal" dmx-multi="true" dmx-populate="">
					<div id="record2" is="dmx-repeat" dmx-bind:repeat="">
						<div class="form-group row">

							<div class="col-sm-10">
								<input type="hidden" class="form-control" dmx-bind:id="insp_c_id_{{$index}}" dmx-bind:name="record2[{{$index}}][c_id]" dmx-bind:value="c_id"
									dmx-on:updated="datastore1.insert({c_name: c_name, c_qty: c_qty, c_cost: c_cost, c_list: c_list, c_part_no: c_Part_no,c_total:(c_cost*c_qty), c_id: c_id})">

Hi @Patrick, I must be thick or stupid, I really can’t get this to work at all despite the very useful information supplied by yourself. Can you please help and give me some further guidance?

Hi @Patrick, I did get this to work at one point, but I don’t know what went wrong and it stopped working. I decided to recreate it the way you suggested.

<div class="input-group col-sm-12" dmx-bind:id="sd_set_{{$index}}" dmx-repeat:sd_set="">
<input type="text" id="sd_set_input" name="text1_{{$index}}" value="" class="form-control" style="max-width: 100px;" dmx-bind:id="Test1_{{$index}}" dmx-bind:name="sd_id" dmx-bind:value="sd_id" dmx-on:updated="specialist_data.upsert({sd_id: sd_id},{sd_id: sd_id, sd_name: sd_name, sd_value: sd_value})">

But this doesn’t work. If I change the dmx-on:updated to dmx-on:click and I click on the INPUT field then it does works.

Could there be something wrong with dmx-on:updated not triggering or recognising that the INPUT field has changed?

Is it something I have done wrong?
Is it something in Wappler not working (I doubt this one :smile:)
Is there an alternative I can use to populate a Data Store on page load?

Crude test screenshots
after load of page


after pressing on of the INPUT fields


Windows 10, MySQL, PHP


I did have an issue with variables and array keys all with same name. I have changed these and the issue is still there where it still won’t UPSERT the Data Store on page load.

An On-Click UPSERT used later on the same page, which works, looks like this (without single quotes)…

dmx-on:click="specialist_data.upsert({sd_id: specialist_id}, {sd_id: specialist_id, sd_name: specialist_name, sd_value: specialist_radio.value})"

Hi @patrick, I am really sorry to ask you directly but is there any guidance you can give me on this issue?

I cannot get Data Store UPSERT to trigger on page load.

Updated is triggered after the input value changed, but only if it was a user action, it doesn’t trigger when it was changed by code.

Where do you have the event for this, should work fine with the load event on the body tag.

Really appreciate the quick reply, thanks. I had the event on Input Updated but as the first part of your answer clearly states that that will not work, I would like to explore the Body Load Event. My problem now is that I am using SPA pages and my BODY tag is in the parent page. Is this where I need to put the Load Event?

I am not sure how to add the

specialist_data.upsert({sd_id: varsplit_sd_id},{sd_id: varsplit_sd_id, sd_name: varsplit_sd_name, sd_value: varsplit_sd_value})

to the Load Event. Would I simply put something like this on the parent page?

<body dmx-on:load="specialist_data.upsert({sd_id: varsplit_sd_id},{sd_id: varsplit_sd_id, sd_name: varsplit_sd_name, sd_value: varsplit_sd_value})">

Sorry if I am way off the mark with this but I just can’t get my head around it.

My current set-up : SPA Pages, Windows 10, MySQL, PHP