Power Automate & Logic Apps: Constructing an iCalendar Description

If you’ve ever tried to automate the creation of an .ics file in Power Automate, you might have been frustrated by the RFC 5545 specification that lines must be no greater than 75 octets.

To construct DESCRIPTION or X-ALT-DESC parameters longer than 75 characters you must add a line break at least every 75 chars, followed by a space.

If your description is, or contains, dynamic content, you need a way to automate that process.

To this end, I’ve developed a function in Power Automate to do it. Unfortunately because it uses a few variables, we can’t drop it all in a scope to copy and paste between flows or logic apps, but the meat of it is in a Do until loop, which can be copied with its contents, plus some variables to copy/paste or manually add first.

Anyway, here we go:

Let’s start with the source text being the starting value of a string variable:

Now, an array and a boolean variable with default value of false:

Now a Do until (or Until if you’re in Logic Apps). We run this loop until that boolean variable is equal to true:

Now, within the loop, add a Compose, then append to array variable. For the compose, we take the first 70 characters of the source string variable (strSourceText) using substring(), then for the append to array variable, push the compose output onto the array we initialised earlier. It’s not clear from the screen shot but there’s a space character at the beginning of the Value property of the append action, before the dynamic content. Each line we push onto the array must start with a space.

Still within the Do until loop, use substring() again to get the rest of the string variable (minus the first 70 characters). In this substring() function, the start index is 70 and the length is the length of the whole string minus 70. We then set the string variable to that, ready to go back into the top of the next loop:

Lastly, we need to check if there are any more lines and exit the loop if not. What’s happening here is we’re measuring the length of the string variable (the remainder of the string that has not yet been pushed onto the array). If the length of that is equal or less that 70, then it’s the last bit, so push it onto the array. Don’t forget to precede the Value input of the append action with a space – iCalendar needs it! Then set the boolean to true, which tells the Do until loop to stop. If it’s longer than 70 chars, there’s more to go, so do nothing and let the loop repeat.

Now the loop is done, we have another action to complete outside of the Do until. Add a Join action and put the array variable as the input. The thing to join on is a line break. Just click in the box and press Enter,

Now when we run the test, the Do until runs for as along as it needs to get to the end of the string and the Join output can be used as dynamic content for DESCRIPTION or X-ALT-DESC in the .ics file.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s