Skip to main content
Community site session details

Community site session details

Session Id : R/HCWZiz7FJo5BtiBVYkIl
Power Automate - Building Flows
Unanswered

Join multiple strings into array

Like (0) ShareShare
ReportReport
Posted on 28 Nov 2018 16:38:52 by 4

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

 

  • Ines Profile Picture
    4 on 04 Dec 2018 at 15:59:47
    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!

  • v-yuazh-msft Profile Picture
    on 29 Nov 2018 at 03:32:32
    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Tomac Profile Picture

Tomac 986 Moderator

#2
stampcoin Profile Picture

stampcoin 699 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 577 Super User 2025 Season 2