0

I'm trying to add newline in String using Logic App. But I got nothing interesting.

That is what I got:

ios-youtube, keepassium-ios, markmcguill-strongbox, Office-Word, microsoft-azureauthenticator, microsoft-scmx, Office-Excel, microsoft-skydrive, Office-Powerpoint, spotify-client, Office-Word, microsoft-onenote, uhhhmagine-flannl, robbie-HomeAssistant, rdc-ios, microsoft-skydrive, skype-teams, miketigas-OnionBrowser, netflix-Netflix, bjoerndemming-aldisued, delius-klasing-bike-app, delius-klasing-tour, heise-ch-magazin, heise-ct-magazin, heise-news4, online-norma, sec-lidl, delius-klasing-ios, robbie-HomeAssistant

I tried these.

enter image description here

enter image description here

and I want the result in this form.



- ios-youtube, 
- keepassium-ios, 
- markmcguill-strongbox, 
- Office-Word, 
- microsoft-azureauthenticator,
- microsoft-scmx, Office-Excel,
- microsoft-skydrive, 
- Office-Powerpoint, 
- spotify-client, 
- Office-Word, 
- microsoft-onenote, 
- uhhhmagine-flannl, 
- robbie-HomeAssistant, 
- rdc-ios, 
- microsoft-skydrive, 
- skype-teams, 
- miketigas-OnionBrowser, 
- netflix-Netflix, 
- bjoerndemming-aldisued, 
- delius-klasing-bike-app, 
- delius-klasing-tour, 
- heise-ch-magazin, 
- heise-ct-magazin, 
- heise-news4, 
- online-norma, 
- sec-lidl, 
- delius-klasing-ios, 
- robbie-HomeAssistant
Skin
  • 9,085
  • 2
  • 13
  • 29
SmartGuy
  • 5
  • 2
  • I remember having the issue, but can't remember which logicapp I had it in. Have you tried opening notepad++ enable special characters, then select from the end of one line to beginning of the next line. Then copy using [ctrl]+[c] and paste it into the concat instead of \n. Another one is to also try \r\n instead of just \n. – Monofuse Jul 20 '23 at 20:30

2 Answers2

1

This basic flow shows you a fairly simple approach that should get you over the line.

Flow

Flow

The expression in the second step looks like this (noting the hyphen at the start in the image to cater for the very first record) ...

replace(variables('String'), ', ', ',
- ')

... but when I entered it, I put it in like this ...

    replace(variables('String'), ', ', ',\n- ')

To achieve that, you need to go into the Code View and edit the definition and change \\n to \n. Reason being, when you enter it through the designer, it's not what you're after. The code view will looks like this ...

"Initialize_Enhanced_String": {
    "inputs": {
        "variables": [
            {
                "name": "Enhanced String",
                "type": "string",
                "value": "- @{replace(variables('String'), ', ', ',\\n- ')}"
            }
        ]
    },
    "runAfter": {
        "Initialize_String": [
            "Succeeded"
        ]
    },
    "type": "InitializeVariable"
}

... and that isn't correct. Remove the second slash will get you across the line.

Result

Result

Skin
  • 9,085
  • 2
  • 13
  • 29
0

I have reproduced in my environment and got expected results as below:

Design:

enter image description here

Then initialized an empty variable and the composed variable 1 with split(variables('var1'),','):

enter image description here

Then in ForEach loop taken input (compose 1 output) then in action used concat in composeconcat('- ',items('For_each')) and then appended var2 and then joined it with new line(just press enter):

enter image description here

Output:

enter image description here

enter image description here

Codeview:

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "@split(variables('var1'),',')",
                "runAfter": {
                    "Initialize_variable_2": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "For_each": {
                "actions": {
                    "Append_to_array_variable": {
                        "inputs": {
                            "name": "var2",
                            "value": "@outputs('Compose_2')"
                        },
                        "runAfter": {
                            "Compose_2": [
                                "Succeeded"
                            ]
                        },
                        "type": "AppendToArrayVariable"
                    },
                    "Compose_2": {
                        "inputs": "@concat('- ',items('For_each'))",
                        "runAfter": {},
                        "type": "Compose"
                    }
                },
                "foreach": "@outputs('Compose')",
                "runAfter": {
                    "Compose": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "var1",
                            "type": "string",
                            "value": "ios-youtube, keepassium-ios, markmcguill-strongbox, Office-Word, microsoft-azureauthenticator, microsoft-scmx, Office-Excel, microsoft-skydrive, Office-Powerpoint, spotify-client, Office-Word, microsoft-onenote, uhhhmagine-flannl, robbie-HomeAssistant, rdc-ios, microsoft-skydrive, skype-teams, miketigas-OnionBrowser, netflix-Netflix, bjoerndemming-aldisued, delius-klasing-bike-app, delius-klasing-tour, heise-ch-magazin, heise-ct-magazin, heise-news4, online-norma, sec-lidl, delius-klasing-ios, robbie-HomeAssistant\n"
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            },
            "Initialize_variable_2": {
                "inputs": {
                    "variables": [
                        {
                            "name": "var2",
                            "type": "array"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Join": {
                "inputs": {
                    "from": "@variables('var2')",
                    "joinWith": "\n"
                },
                "runAfter": {
                    "For_each": [
                        "Succeeded"
                    ]
                },
                "type": "Join"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}
RithwikBojja
  • 5,069
  • 2
  • 3
  • 7