1

I have a specific question regarding line breaks in SharePoint online lookup columns in which multiple values are allowed. I would like to separate each of the values from lookup via a line break.

I tried the following in the JSON formatting window:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=replace(@currentField,';','\n')"
}  

Unfortunately, this configuration only allows line break after the first value by replacing the ";", the others remain as before.

Does anyone know how this can be fixed. Thanks a lot in advance for your support, highly appreciated

0

You can use below JSON code to show each value on separate line:

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
   "elmType": "div",
   "txtContent": "=join(@currentField, '\n')"
}

Check my full answer at: Organize multi-choice user inputs by separate line (not comma)

Alternatively if you want to apply formatting to each value then you can use ForEach and Iterators in JSON formatting as given here.

1
  • Thanks for the immediate response to my request. Unfortunately, this strategy ("txtContent": "=join(@currentField, '\n')") does not solve my problem. Your code does work for multiple choice columns BUT not for look up columns in which multiple values are displayed, in particular not for additonal look up fields which are displayed. Do you have any other suggestions? Introducing the for each function might help but how do I implement this into the full code? Thanks in advance. Best Regards Jan
    – Jan
    Dec 2 '20 at 9:41
0

Please follow steps:

  1. Create a Choice Type column and allow multiple value

enter image description here

  1. Try using below JSON code on your choice field:

    { "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "=join(@currentField, '\n')" }


Note:

  • join() takes 2 operands. The first is an array (multi-select person or choice field) and the second is the separating string.
  • Returns a string concatenation of the array values separated by the separating string.

  1. When you create a new item in the list, the effect shown below will appear:

enter image description here

Reference for operators you can use in JSON formatting, JSON formatting - Operators.

………………………………………………Updated Answer…………………………………………

There are two ways:

1.Use the out-of-the-box feature

  • Go to the specific List, create a Lookup column. enter image description here
  • Then, scroll page to Additional Column Settings section. Please select the "Allow multiple values" checkbox. enter image description here

2.Try below JSON formatting on your multi-lookup column in list view to show data vertically:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "debugMode": true,
  "elmType": "div",
  "children": [
    {
      "elmType": "div",
      "style": {
        "display": "block",
        "width": "100%"
      },

      "txtContent": "=join(@currentField.lookupValue, '\n')"
    }
  ]
}
4
  • Thanks for the immediate response to my request. Unfortunately, this strategy ("txtContent": "=join(@currentField, '\n')") does not solve my problem. Your code does work for multiple choice columns BUT not for look up columns in which multiple values are displayed, in particular not for additonal look up fields which are displayed. Do you have any other suggestions? Thanks in advance. Best Regards Jan
    – Jan
    Dec 2 '20 at 9:45
  • I have updated my answer, hope this helps you. Have a nice day! Dec 3 '20 at 6:31
  • Dear Echo Du, thanks again for your answer, unfortunately this option is also not working, the implemented line breaks are felxible depending on the column width manually adjusted. for my use case I need static line break which does not change after implementation. E.g. 4 multiple entries always have to be displayed in four lines. Thanks again for your efforts. Best Regards
    – Jan
    Dec 7 '20 at 10:09
  • Hi, Jan. According to my research and testing these days, the Lookup field format is not support static line break in SharePoint Online. By design, if the Lookup column allows multiple values, the field value will be displayed in the form of one value per line. Dec 11 '20 at 6:24
0

For anyone looking this up... Use a "replace" function instead of "join"! In my case, my multiple lookup values were a single string separated by ";". What I did to separate them into separate lines was this:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=replace(@currentField,';',',\n')"
}

With this solution, it doesn't matter how wide you make the column. The items will always be separated by a new line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.