cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Ines
Level: Powered On

Join multiple strings into array

Hi everyone,

I'm trying to build a flow that would ultimately create purchase records in my Knack database for each Shopify order. Shopify orders support line items and I'd like to create one record for each item.

 

So here's what I got:

Shopify sample outputs:

  • Line Item SKU: ex1, ex2
  • Line Item Qty: 1, 2
  • Line Item Price: $10, $20

Now I'd like to create an array in Flow that looks something like this:

[
  {
     "SKU": "ex1",
     "Qty": 1,
     "Price": "$10"
  },
  {
     "SKU": "ex2",
     "Qty": 2,
     "Price": "$20"
  }
]

And this should help me create 2 records in my database.

 

I tried using Compose with split() to split the strings into an array, and then Select to map the outputs like this:

2018-11-28_17-28-47.png

 

Then I ended up with 3 Selects that look like this:

2018-11-28_17-28-29.png

 

... so this obviously won't help me achieve what I'm after - the end result is an array with 9 "records", each with either SKU, or Qty, or Price field filled in.

 

If anyone can help me figure out how to split/combine these separate strings into a workable array, I'd very much appreciate it!

 

Cheers

 

2 REPLIES 2
Community Support Team
Community Support Team

Re: Join multiple strings into array

Hi @Ines,

 

You said that you use Compose with split() to split the strings into an array, could you please share more details about the strings?

 

And do you want to Join multiple strings to array as below:

[
  {
     "SKU": "ex1",
     "Qty": 1,
     "Price": "$10"
  },
  {
     "SKU": "ex2",
     "Qty": 2,
     "Price": "$20"
  }
]

Please share the strings with us so we woyuld try to provide a proper workaround for you.

 

Best regards,

Alice

Ines
Level: Powered On

Re: Join multiple strings into array

Hi Alice, apologies for the delay and thank you for your reply. I managed to figure this out with a possibly convoluted set of actions, but here it is in case it helps anyone:

 

Each item has it's own SKU code, quantity, price, etc. This information is being passed to my flow in string groups like this:

(Text Field 1) SKU: skuCode1,skuCode2,skuCode3...
(Text Field 2) Qty: qty1,qty2,qty3...
(Text Field 3) Price: price1,price2,price3...

And my end result needs need to be like this:

[
   {
       "SKU": "skuCode1",
       "Qty": "qty1",
       "Price": "price1"
   },
   {
       "SKU": "skuCode2",
       "Qty": "qty2",
       "Price": "price2"
   },
   {
       "SKU": "skuCode3",
       "Qty": "qty3",
       "Price": "price3"
   }

 

---

Solution:

1. Create a Compose action for the first field (SKU). Compose action:

split(triggerBody()?['SKU'],',')

2. Create an array variable with initial value set to:

outputs('Compose_SKU')

1.png

The initial value of array ArraySKU is:

{
   skuCode1,
   skuCode2,
   skuCode3,
   ...
}

3. Create (1) and (2) for each field that contains details that need to be put in the final array. So e.g. Compose_Qty / Array_Qty, Compose_Price / Array_Price, Compose_Name / Array_Name, etc.

4. Create an integer variable which will be used to select a specific element from the arrays. Initial value set to 0.

5. Create an "Apply to each" loop for the output of Compose_SKU action (because that's effectively my total number of items) and write the array for fields as follows:

{
  "SKU": =if(equals(length(variables('ArraySKU')),0),'',variables('ArraySKU')[variables('CounterArray')]),
  "Qty": =if(equals(length(variables('ArrayQty')),0),'',variables('ArrayQty')[variables('CounterArray')]),
  "Price": =if(equals(length(variables('ArrayPrice')),0),'',variables('ArrayPrice')[variables('CounterArray')]),
   ...
}

i.e. if ArrayXYZ is empty, return nothing, else return nth item of the array, where n is determined by the counter variable from step 4.

6. At the end of the loop, increment Counter variable.

(Note: the HTTP in my example could also be replaced with "append to array" but it would've been an unnecessary step for my flow.)

2a.png

---

Final flow looks like this:

3a.png

 

Cheers!

Helpful resources

Announcements
firstImage

Microsoft Flow Online Conference

Join us for a FULL day of FREE Microsoft Flow Sessions from some of the best minds in the industry!

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020

thirdimage

Flow Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

thirdImage

New Flow Community Board!

Check out the new Microsoft Flow Community Blog Topic Suggestion board!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 47 members 4,174 guests
Please welcome our newest community members: