How to display multiple Lookup column values on one line whilst retaining the links - sharepoint-online

By default, the values in a Lookup column display as links.
Clicking on these links takes you to the relevant item in the lookup list.
When setting the column to Allow multiple values, each value is displayed on a separate line.
To make the values appear on one line, I have applied this column formatting:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=join(#currentField.lookupValue, ', ')"
}
This results in the desired behavior of the values being on one line, separated by commas, eg:
Value1, Value2, Value3
However, the values are just plain text, ie the links have been removed.
How can I retain the links for each of the values, whilst still displaying them on one line.
Edit 1:
It seems that Lookup columns have two properties available via column formatting:
.lookupValue
.lookupId
When you click on a link in a Lookup column, it goes to a URL with this structure:
https://tenant-name.sharepoint.com/sites/site-name/Lists/Some%20List/DispForm.aspx?ID=n
Where the n at the end of the URL is the lookupId.
So one possible solution would be to:
use .lookupId to get the ID of the item in the lookup list
for each value in the lookup column, construct the URL and concatenate the .lookupId value to the end
Using this post an inspiration, the following code almost works, but the ID value in each of the links is output as the same (and is also incorrect):
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"children": [
{
"elmType": "a",
"style": {
"display": "block",
"width": "100%"
},
"txtContent": "=join(#currentField.lookupValue, ', ')",
"attributes": {
"target": "_blank",
"href": "='https://tenant-name.sharepoint.com/sites/site-name/Lists/Some%20List/DispForm.aspx?ID=' + [$ID]"
}
}
]
}
Edit 2:
Based on this answer, which references this blog post, the following achieves the desired behaviour using forEach, but it adds a trailing comma on the end of all last values in the column:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"children": [
{
"forEach": "lookupIterator in #currentField",
"elmType": "a",
"txtContent": "=[$lookupIterator.lookupValue] + ', '",
"attributes": {
"target": "_blank",
"href": "='https://tenant-name.sharepoint.com/sites/site-name/Lists/Some%20List/DispForm.aspx?ID=' + [$lookupIterator.lookupId]"
}
}
]
}
Below is another way to do it using operator and operands but it still shows the undesired trailing comma:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"children": [
{
"forEach": "lookupIterator in #currentField",
"elmType": "a",
"txtContent": {
"operator": "+",
"operands": [
"[$lookupIterator.lookupValue]", ", "
]
},
"attributes": {
"target": "_blank",
"href": "='https://tenant-name.sharepoint.com/sites/site-name/Lists/Some%20List/DispForm.aspx?ID=' + [$lookupIterator.lookupId]"
}
}
]
}
I don't know if it's possible to somehow define different concatenation on the last item in the loop, with something like:
"=if(loopIndex('lookupIterator') == length(#currentField - 1), 'DON'T ADD COMMA', 'DO ADD COMMA')"

This seems to work:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"children": [
{
"forEach": "lookupIterator in #currentField",
"elmType": "a",
"txtContent": "=if(loopIndex('lookupIterator') == length(#currentField) - 1, [$lookupIterator.lookupValue], [$lookupIterator.lookupValue] + ', ')",
"attributes": {
"target": "_blank",
"href": "='https://tenant-name.sharepoint.com/sites/site-name/Lists/Some%20List/DispForm.aspx?ID=' + [$lookupIterator.lookupId]"
}
}
]
}
It uses forEach, an if() statement, loopIndex and length() to concatenate values conditionally, i.e:
if it's the last item in the loop, don't add the separating comma
if it's not the last item in the loop, do add the separating comma
To be honest, i'm surprised the conditional structure worked in there, and the referenced column values as well.
Bonus
It seems you can also add a style property under txtContent which uses the same conditional logic, just to make the gap between values larger than the default 1 space character, i.e:
"style": {
"padding-right": "=if(loopIndex('lookupIterator') == length(#currentField) - 1, '0px', '5px'"
},

Related

Power Automate FIlter Array with Array Object as Attribute

i have a Object-Array1 with some Attributes that are Object-Array2. I want to filter my Object-Array1 only to these elements, that contain a special value in Object-Array2. How wo i do this? Example:
{
"value": [
{
"title": "aaa",
"ID": 1,
"Responsible": [
{
"EMail": "abc#def.de",
"Id": 1756,
},
{
"EMail: "xyz#xyz.com",
"Id": 289,
}
]
},
{
"title": "bbbb",
"ID": 2,
"Responsible": [
{
"EMail": "tzu#iop.de",
"Id": 1756,
}
]
}
]
}
I want to filter my Object-Array1 (with title & id) only to these elements, that contain abc#def.de
How do i do this in Power Automate with the "Filter Array" Object? I tried this way, but didn't work:
Firstly, you haven't entered an expression, you've entered text. That will never work.
Secondly, even if you did set that as an expression, I don't think you'll be able to make it work over an array, at least, not without specifying more properties and making it a little more complex.
I think the easiest way is to use a contains statement after turning the item into a string ...
The expression I am using on the left hand side is ...
string(item()?['Responsible'])
... and this is the result ...

SharePoint column formatting referring to Hyperlink Column

In my list, I am referring to a hyperlink column on whether or not to show a field in a different column. My hyperlink field name is "Link to Site", so the internal name is "Link_x0020_to_x0020_Site".
I cannot get the logic to show/hide appropriately based on whether the Url in the hyperlink is empty or not - here is the beginning of my json:
{
"$schema": "https: //developer.microsoft.com/en-us/json-schemas/sp/column-formatting.schema.json",
"elmType": "span",
"style": {
"color": "#0078d7",
"display": "=if([$Link_x0020_to_x0020_Site]=='', '', 'none'"
},
If you want to show the span element if hyperlink column is empty, use in this format:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "span",
"style": {
"color": "#0078d7",
"display": "=if([$Link_x0020_to_x0020_Site] == '', 'inherit', 'none')"
},
If you want to hide the span element if hyperlink column is empty, use in this format:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "span",
"style": {
"color": "#0078d7",
"display": "=if([$Link_x0020_to_x0020_Site] == '', 'none', 'inherit')"
},
You can also try using block if inherit is not working for you.

convert a list of strings to list of type dynamic

Im trying to use a MultiSelectFormField to create a drop down list with multiple choices.The datasource for the MultiSelectFormField is required in the below format,
dataSource:[
{
"display": "Running",
"value": "Running",
},
{
"display": "Climbing",
"value": "Climbing",
},
{
"display": "Walking",
"value": "Walking",
},
],
but what I have is a list of type string containing the value sthat should be displayed in the drop down.My question is how can I convert
list<String> dropDownValues=["Running","Climbing","Walking"]
to the format required
Please use the map operator
final dropDownValues=["Running","Climbing","Walking"];
final data = dropDownValues.map((el) => {"display": el,"value" el,}).toList();

Unable to fetch the entire column index based on the value using JSONPath finder in npm

I have the below response payload and I just want to check the amount == 1000 if it's matching then I just want to get the entire column as output.
Sample Input:
{
"sqlQuery": "select SET_UNIQUE, amt as AMOUNT from transactionTable where SET_USER_ID=11651 ",
"message": "2 rows selected",
"row": [
{
"column": [
{
"value": "22621264",
"name": "SET_UNIQUE"
},
{
"value": "1000",
"name": "AMOUNT"
}
]
},
{
"column": [
{
"value": "226064213",
"name": "SET_UNIQUE"
},
{
"value": "916",
"name": "AMOUNT"
}
]
}
]
}
Expected Output:
"column": [
{
"value": "22621264",
"name": "SET_UNIQUE"
},
{
"value": "1000",
"name": "AMOUNT"
}
]
The above sample I just want to fetch the entire column if the AMOUNT value will be 1000.
I just tried below to achieve this but no luck.
1. row[*].column[?(#.value==1000)].column
2. row[*].column[?(#.value==1000)]
I don't want to do this by using index. Because It will be change.
Any ideas please?
I think you'd need nested expressions, which isn't something that's widely supported. Something like
$.row[?(#.column[?(#.value==1000)])]
The inner expression returns matches for value==1000, then the outer expression checks for existence of those matches.
Another alternative that might work is
$.row[?(#.column[*].value==1000)]
but this assumes some implicit type conversions that may or may not be supported.

Calling Instant Flow from SharePoint formatted column

I am trying to make a call to a Power Automate Instant Flow from a formatted column. I'm taking my inspiration from this article - https://www.inspiribytes.com/power-automate/deploying-a-single-flow-to-multiple-sharepoint-libraries-lists/
I set up the column with the json:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "button",
"customRowAction": {
"action": "executeFlow",
"actionParams": "{\"id\": \"0aa2105b-755e-4017-aac8-b1b823ea96d1\"}"
},
"attributes": {
"class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"
},
"style": {
"border": "none",
"background-color": "transparent",
"cursor": "pointer"
},
"children": [
{
"elmType": "span",
"attributes": {
"iconName": "Flow"
},
"style": {
"padding-right": "6px"
}
},
{
"elmType": "span",
"txtContent": "Start Approval"
}
]
}
I created my Instant FLow, and noted the ID in the URL and changed the JSON in the formatted column to match.
When I click the button, I see a message that says "Setting Up" - clicking it, it just says "Waiting"
When I review the Developer Console, I see the following message:
POST https://prod-176.westus.logic.azure.com/workflows/b294beca8451414787bae052f8be6181/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=8s7N19sj-J3iZjMy90RvM7xKkcvujUkQCBPWxB6rZcc 400
So I'm getting a Bad Request, but I cannot figure out why. There doesn't appear to be any other parameters that I should be setting other than the ID of the workflow.
In my test, I cannot reproduce your problem.
There is no problem with your JSON code. I suggest you provide the screenshots of your flow, which will help us solve the problem better.

Resources