cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Parsing a string

Hi all, 

 

Currently I have a very long string I pass into my Flow from PowerApps, and I am trying to parse the string. The string I pass in was originally a collection in PowerApps, consisting of different calendar events and its corresponding information (Title of event, start time, and end time). In the string, the columns (details per each event) are separated by commas, and the different rows (different events) are separated by a semi-colon.

 

Here is an example of how two events are concatenated and passed into Flow:   

Attend Workshop,11/12/2019 1:30 PM, 11/12/2019 2:30 PM; Pick up kids, 1/12/2019 2:00 PM, 1/12/2019 3:00 PM; 

 

My flow diagram is super long in order to execute everything I need, so I wont post a picture for your sake. However, I do have a variable that keeps track of the current position (ideally would get updated to the index after each comma/semi-colon), a variable holding the index of the comma/semi-colon, and variables holding the substrings. 

 

I know I can use the indexOf() expression to find the first comma in the string. However, how would I re-write this, or use another expression, to then find the next comma in my string? 

 

My goal is to parse the title, start time, and end time for each event, and upload to outlook calendar until all events have been added from the long string. 

 

Thank you,

Kenzie

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
v-bacao-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can use WDL function to parse this data.

For example, the data obtained from PowerApps is the following. I use Input to input these data as an example.

Attend Workshop, 11/12/2019 1:30 PM, 11/12/2019 2:30 PM; Pick up kids, 1/12/2019 2:00 PM, 1/12/2019 3:00 PM;

 

  • Use split() function to separate the events into single event and configure Apply to each to traverse each event.
split(triggerBody()['text'],';')
  • Configure Condition to exclude the last empty element in the array.
  • Use split() function again to separate the properties in a single event.

Split:

split(items('Apply_to_each'),',')
  • Use the array index to get the property value of the event separately.

Title:

outputs('Split')[0]

Start Time:

outputs('Split')[1]

End Time:

outputs('Split')[2]
  • Finally, these properties are configured in Create event action.

Image reference:

12.PNG13.PNG16.PNG

Hope it helps.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

MarkStokes
Skilled Sharer
Skilled Sharer

Since  you are passing this in from PowerApps you are probably in control of the string that gets passed over.

 

If I was you I would create your string as a JSON object. Yep, sorry, this just got a bit "technical" but it will save you a ton of pain if you can get your head around it.

 

Your event data would then look like this in PowerApps, which you would send to Flow.

[
  {
    "title": "Attend Workshop",
    "starttime": "2019-12-11T13:30:00",
    "endtime": "2019-12-11T14:30:00"
  },
  {
    "title": "Pick up kids",
    "starttime": "2019-12-01T14:00:00",
    "endtime": "2019-12-01T15:00:00"
  }
]

Now, in Flow you can use the Parse JSON Action, Paste in this sample JSON to have it generate a schema for you (by using that little link under the Parse JSON Schema text box.

 

Now, in your following Flow Actions you will be able to access the properties of your JSON objects (and do an Apply to Each on it) to make your life super easy.

 

Oh, I also changed your dates and times to a UTC format to make them a LOT easier to work with.

 

-Mark

View solution in original post

3 REPLIES 3
v-bacao-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can use WDL function to parse this data.

For example, the data obtained from PowerApps is the following. I use Input to input these data as an example.

Attend Workshop, 11/12/2019 1:30 PM, 11/12/2019 2:30 PM; Pick up kids, 1/12/2019 2:00 PM, 1/12/2019 3:00 PM;

 

  • Use split() function to separate the events into single event and configure Apply to each to traverse each event.
split(triggerBody()['text'],';')
  • Configure Condition to exclude the last empty element in the array.
  • Use split() function again to separate the properties in a single event.

Split:

split(items('Apply_to_each'),',')
  • Use the array index to get the property value of the event separately.

Title:

outputs('Split')[0]

Start Time:

outputs('Split')[1]

End Time:

outputs('Split')[2]
  • Finally, these properties are configured in Create event action.

Image reference:

12.PNG13.PNG16.PNG

Hope it helps.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
MarkStokes
Skilled Sharer
Skilled Sharer

Since  you are passing this in from PowerApps you are probably in control of the string that gets passed over.

 

If I was you I would create your string as a JSON object. Yep, sorry, this just got a bit "technical" but it will save you a ton of pain if you can get your head around it.

 

Your event data would then look like this in PowerApps, which you would send to Flow.

[
  {
    "title": "Attend Workshop",
    "starttime": "2019-12-11T13:30:00",
    "endtime": "2019-12-11T14:30:00"
  },
  {
    "title": "Pick up kids",
    "starttime": "2019-12-01T14:00:00",
    "endtime": "2019-12-01T15:00:00"
  }
]

Now, in Flow you can use the Parse JSON Action, Paste in this sample JSON to have it generate a schema for you (by using that little link under the Parse JSON Schema text box.

 

Now, in your following Flow Actions you will be able to access the properties of your JSON objects (and do an Apply to Each on it) to make your life super easy.

 

Oh, I also changed your dates and times to a UTC format to make them a LOT easier to work with.

 

-Mark

Hi @v-bacao-msft - thanks for your response above.

 

I have same requirement to parse a string and map the values on basis of indexes.

But, i am facing below error -

'Apply to each' is getting failed - 
ActionFailed. An action failed. No dependent actions succeeded.

 

Error in Compose action -

InvalidTemplate. Unable to process template language expressions in action 'Compose' inputs at line '0' and column '0': 'The template language expression 'outputs('split')[1]' cannot be evaluated because array index '1' is outside bounds (0, 0) of array. Please see https://aka.ms/logicexpressions for usage details.'.

 

AJ_vizMan_0-1643713588169.png

 

Appreciate your help to resolve this.

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power automate tips 768x460 v2.png

Restore a Deleted Flow

Did you know that you could restore a deleted flow? Check out this helpful article.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Users online (3,056)