How to convert a DataStore to a String? Flow is having an unexpected behavior

Hi,

I am on Node.JS and want to pass the content of a DataStore from Frontend to a ServerConnect, hence I am looking to transform the DataStore to a string.

I tried to use page flow for that without success as follows:

Note: the browser alert instructions are here for debugging and they showed an unexpected behavior of flow: The value of CustomerSegmentsTXT variable is reset after each loop of the repeat, resulting in an empty output, similar to the one before the repeat.

How can I add new text to the CustomerSegmentsTXT variable after each loop to get a flattend DataStore at the end of the repeat loop?

Here is the script code for more clarity:

<script is="dmx-flow" id="flow_CustomerSegments_to_string" type="text/dmx-flow">[
  {
    assign: {
      value: "Customer Segments: ",
      name: "CustomerSegmentsTXT",
      output: true
    }
  },
  {
    repeat: {
      repeat: "{{modal_TargetCustomer.ds_CustomerSegments.data}}",
      outputFields: [],
      exec: {
        steps: [
          {
            assign: {
              value: "{{CustomerSegmentsTXT+' '+($index+1)+'/'+name+', Persona: '+overview+', Jobs: '+jobs+', Pains: '+pains+'.'}}",
              name: "CustomerSegmentsTXT",
              output: true
            }
          },
          {
            run: {action: "{{browser1.alert(CustomerSegmentsTXT)}}"}
          }
        ]
      },
      name: "repeat"
    }
  },
  {
    run: {action: "{{browser1.alert(CustomerSegmentsTXT)}}"}
  },
  {
    assign: {
      value: "{{CustomerSegmentsTXT}}",
      name: "CustomerSegmentsTXT",
      output: true
    }
  }
]</script>

I would put a hidden text input inside a standard server connect form, and set its dynamic value to be a stringified version of the data store data using the .toJSON() formatter.

Then the first action of your server connect is to reverse the process…use a set value that is the $_POST.your_hidden_input_name.parseJSON(). This will give you the complete data store as a manageable object. If you set the Data type of the set value to Object, you can then define the keys of your datastore so you can easily pick them in the data pickers.

Here is a post with some details on how this can be accomplished:

3 Likes

Thank loads @mebeingken, it worked perfectly well. I have been struggling with this for a full day :pray:

1 Like