I am using sharepoint online as an image library. I am using 'keywords' to tag each image. The field is a string of delimited values like this:
keyword1;keyword2;keyword3
I would like to format this field value by splitting the string using the semi-colon delimiter and showing each keyword in its own span, so its looks like this:
(keyword 1) (keyword 2) (keyword 3)
I'm not sure if I need to use a calculated column to do this or if it is even possible? I've tried using 'forEach' but i cannot seem to loop through the items - they just render as a single value in a single span?
This is what i'm using at the moment:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
"hideSelection": true,
"tileProps": {
"height": "300",
"width": "300",
"formatter": {
"elmType": "div",
"style": {
"display": "flex",
"flex-wrap": "wrap",
"align-items": "stretch",
"box-shadow": "0 1.6px 3.6px 0 #00000022, 0 0.3px 0.9px 0 #0000001c",
"min-width": "150px",
"width": "100%",
"margin-bottom": "0",
"border-radius": "3px",
"margin": "0 2px",
"background-color": "#fbfbfb",
"height": "350px"
},
"children": [
{
"elmType": "div",
"style": {
"display": "flex",
"flex-wrap": "wrap",
"position": "relative",
"padding-bottom": "30px",
"width": "100%"
},
"children": [
{
"elmType": "div",
"style": {
"width": "100%",
"background-color": "#e4e4e4",
"overflow": "hidden",
"height": "200px",
"display": "flex",
"align-items": "center",
"justify-content": "center",
"position": "relative"
},
"children": [
{
"elmType": "div",
"style": {
"oveflow": "=if([$File_x0020_Type] == '', 'auto', 'hidden')"
},
"children": [
{
"elmType": "img",
"style": {
"width": "=if([$File_x0020_Type] == '', '100%', '0'",
"height": "=if([$File_x0020_Type] == '', '100px', '0'"
},
"attributes": {
"src": "=if([$File_x0020_Type] == '', 'https://spoprod-a.akamaihd.net/files/fabric/office-ui-fabric-react-assets/foldericons-fluent/folder-large_frontplate_nopreview.svg', '')"
}
},
{
"elmType": "img",
"style": {
"width": "100%",
"height": "100%",
"display": "=if([$File_x0020_Type] == '', 'none', '')"
},
"attributes": {
"src": "#thumbnail.300x300"
},
"defaultHoverField": "[$FileLeafRef]"
}
]
}
]
},
{
"elmType": "div",
"style": {
"margin": "15px 0",
"position": "absolute",
"top": "200px",
"width": "100%"
},
"attributes": {
"class": "ms-fontSize-14 ms-fontWeight-semibold"
}
},
{
"elmType": "div",
"style": {
"display": "flex",
"flex-wrap": "wrap",
"padding": "0 16px",
"line-height": "20px",
"width": "100%"
},
"children": [
{
"elmType": "div",
"style": {
"display": "inline-block",
"flex": "1 0 100%"
},
"children": [
{
"elmType": "div",
"style": {
"color": "#a7a7a7",
"font-weight": "bold"
},
"txtContent": "Keywords"
},
{
"elmType": "div",
"children": [
{
"forEach": "kwIterator in #currentField",
"elmType": "div",
"txtContent": "[$kwIterator]",
"attributes": {
"class": "ms-bgColor-themePrimary ms-fontColor-white",
"title": "='keyword:' + =[$kwIterator]"
},
"style": {
"width": "16px",
"height": "16px",
"text-align": "center",
"margin": "1px"
}
}
]
}
]
},
{
"elmType": "div",
"style": {
"display": "inline-block",
"flex": "1 0 34%"
},
"children": [
{
"elmType": "div",
"style": {
"color": "#a7a7a7"
},
"txtContent": "=if([$AverageRating] >= 5, '*****', if([$AverageRating] >= 4, '****', if([$AverageRating] >= 3, '***', if([$AverageRating] >= 2, '**', if([$AverageRating] >= 1, '*', 'no rating'))))"
},
{
"elmType": "div",
"style": {
"color": "#a7a7a7",
"font-size": "40px"
},
"txtContent": "=if([$AverageRating] >= 5, '*****', if([$AverageRating] >= 4, '****', if([$AverageRating] >= 3, '***', if([$AverageRating] >= 2, '**', if([$AverageRating] >= 1, '*', '-'))))"
}
]
}
]
}
]
}
]
}
}
}
Any pointers to iterate through a delimited list of values would be appreciated.
According to my research, forEach does not support multiple lines of text type.
From this article:
The field used in the loop must be in a supported field type with multi-value option enabled: Person, Lookup, and Choice.
Since all the text in the multi-line text is recognized as a whole, we couldn't split it via ";" and add the link break between them with Json.
Related
I'm new to JSON and would like to seek some advise on following piece of code.
Scenario:
In the following list, would like to trigger a flow for the selected item to move the item to another list once the approver clicks "Approve". Have nested the executeFlow action under "Approve" button. I'm not able to figure out where i'm going wrong, so thought of seeking some advise. (Note: Flow ID is changed.)
List
Thank you for your help, in advance.
JSON Script:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"style": {
"flex-directon": "row",
"justify-content": "left",
"align-items": "center",
"flex-wrap": "nowrap"
},
"children": [
{
"elmType": "div",
"style": {
"display": "=if([$Status] == 'In Progress', 'inherit','none')",
"flex-directon": "row",
"justify-content": "left",
"align-items": "center",
"flex-wrap": "wrap"
},
"children": [
{
"elmType": "button",
"customRowAction": {
"action": "executeFlow",
"actionParams": "{\"id\":\"0000f4409-0081-0016-b459-4f000000001dfd\"}",
"action": "setValue",
"actionInput": {
"Status": "Approved",
"ApprovalDecisionBy": "#me"
}
},
"attributes": {
"class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"
},
"style": {
"border": "none",
"background-color": "transparent",
"cursor": "pointer",
"display": "flex",
"flex-directon": "row",
"justify-content": "left",
"align-items": "center",
"flex-wrap": "wrap"
},
"children": [
{
"elmType": "span",
"attributes": {
"iconName": "SkypeCircleCheck"
},
"style": {
"padding": "4px"
}
},
{
"elmType": "span",
"txtContent": "Approve",
"style": {
"word-break": "keep-all"
}
}
]
},
{
"elmType": "button",
"customRowAction": {
"actionInput": {
"Status": "Not Approved",
"ApprovalDecisionBy": "#me"
}
},
"attributes": {
"class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"
},
"style": {
"border": "none",
"background-color": "transparent",
"cursor": "pointer",
"display": "flex",
"flex-directon": "row",
"justify-content": "left",
"align-items": "center",
"flex-wrap": "wrap"
},
"children": [
{
"elmType": "span",
"attributes": {
"iconName": "Blocked"
},
"style": {
"padding": "4px"
}
},
{
"elmType": "span",
"txtContent": "Reject",
"style": {
"word-break": "keep-all"
}
}
]
}
]
},
{
"elmType": "div",
"children": [
{
"elmType": "span",
"txtContent": "='This item is ' + toLowerCase([$Status])",
"style": {
"display": "=if([$Status] == '' , 'none','inherit')",
"padding-left": "5px",
"word-break": "keep-all"
}
}
]
}
]
}
It looks like it is not allowed to use two actions in a customRowAction property of a button. When I try to add that in my json I am getting a Duplicate object key warning.
As a workaround I would suggest to simply update the Status and ApprovalDecisionBy fields from your Power Automate flow instead. You can use an update item action for that.
I am having a problem setting the conditional formatting of a SharePoint Form "Header" based on the value of a column. For example, i am wanting the header banner to be "ms-bgColor-greenDark" when the column value for "Risk Status" is set as "Active", "ms-bgColor-yellowDark" when the column value for "Risk Status" is set as "Postponed".... and so on.
My code so far is as follows:
{
"elmType": "div",
"attributes": {
"class": "=if([$Risk_x0020_Status] == 'Active', 'ms-bgColor-greenDark', if([$Risk_x0020_Status] == 'Postponed', 'ms-bgColor-yellowDark', if([$Risk_x0020_Status] == 'Closed', 'ms-bgColor-redDark', 'ms-bgColor-neutralLight')))"
},
"style": {
"width": "99%",
"border-top-width": "0px",
"border-bottom-width": "1px",
"border-left-width": "0px",
"border-right-width": "0px",
"border-style": "solid",
"margin-bottom": "16px"
},
"children": [
{
"elmType": "div",
"style": {
"display": "flex",
"box-sizing": "border-box",
"align-items": "center"
},
"children": [
{
"elmType": "div",
"attributes": {
"iconName": "AlertSettings",
"class": "ms-fontSize-42 ms-fontWeight-regular ms-fontColor-black",
"title": "Risk"
},
"style": {
"flex": "none",
"padding": "0px",
"padding-left": "10px",
"height": "36px"
}
}
]
},
{
"elmType": "div",
"attributes": {
"class": "ms-fontColor-black ms-fontWeight-bold ms-fontSize-24"
},
"style": {
"box-sizing": "border-box",
"width": "100%",
"text-align": "left",
"padding": "21px 12px",
"overflow": "hidden"
},
"children": [
{
"elmType": "div",
"txtContent": "='Risk: ' + [$Title]"
}
]
}
]
}
So far the header simply displays as ms-bgColor-neutralLight regardless of the value in the Risk Status column. AS im very new to JSON, im hoping this is a matter of understanding the syntax.
Any pointers would be most welcome.
I have a customized button column (Test)
I would like to set condition for the button to be shown when the file type = folder only.
Below is my Json code but unfortunately it doesn't works.
{
"$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
"elmType": "button",
"customRowAction":
{
"action": "executeFlow",
"actionParams": "{\"id\": \"\"}"
},
"style": {
"border": "none",
"background-color": "transparent",
"color": "#0078d7",
"cursor": "pointer",
"display": "=if( ([$Type] == 'Folder' ), 'block', 'none')"
},
"children": [
{
"elmType": "span",
"attributes": {
"iconName": "FollowUser"
},
"style": {
"padding-right": "6px"
}
},
{
"elmType": "span",
"txtContent": "click to start"
}
]
}
There is a content type column in SharePoint Library, you can judge the value of this column to determine whether to display this button.
{
"$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
"elmType": "button",
"customRowAction":
{
"action": "executeFlow",
"actionParams": "{\"id\": \"\"}"
},
"style": {
"border": "none",
"background-color": "transparent",
"color": "#0078d7",
"cursor": "pointer",
"display": "=if( ([$ContentType] == 'Folder' ), 'block', 'none')"
},
"children": [
{
"elmType": "span",
"attributes": {
"iconName": "FollowUser"
},
"style": {
"padding-right": "6px"
}
},
{
"elmType": "span",
"txtContent": "click to start"
}
]
}
Test result:
I have been trying to get a profile picture to appear in a modern list on SharePoint using the "People" column type, this works fine in classic SharePoint but doesn't in the modern list. So I've turned to customising the column using JSON and the example from here (same code below)
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"children": [
{
"elmType": "div",
"style": {
"width": "32px",
"height": "32px",
"overflow": "hidden",
"border-radius": "50%"
},
"children": [
{
"elmType": "img",
"attributes": {
"src": "='/_layouts/15/userphoto.aspx?size=S&accountname=' + #currentField.email",
"title": "#currentField.title"
},
"style": {
"position": "relative",
"top": "50%",
"left": "50%",
"width": "100%",
"height": "auto",
"margin-left": "-50%",
"margin-top": "-50%"
}
}
]
}
]
}
This works great with the exception that if the field is empty it gets populated with the default profile picture place holder image as you can see here
People column showing default place holders
My question is there any way I can suppress this image so if the field is empty it looks empty on the list view?
Thanks.
Try this.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"children": [
{
"elmType": "div",
"style": {
"width": "32px",
"height": "32px",
"overflow": "hidden",
"border-radius": "50%"
},
"children": [
{
"elmType": "img",
"attributes": {
"src": "=if(length(#currentField.email)==0, '', '/_layouts/15/userphoto.aspx?size=S&accountname=' + #currentField.email)",
"title": "=if(length(#currentField.email)==0,'',#currentField.Title)"
},
"style": {
"position": "relative",
"top": "50%",
"left": "50%",
"width": "100%",
"height": "auto",
"margin-left": "-50%",
"margin-top": "-50%"
}
}
]
}
]
}
I am using SharePoint online and would like to use row formatting on a document library.
Ideally i like the tile view for the documents. However, it only shows the "name" of the file. I would like to use the Title instead of the Name and i prefer to keep the same tile view style.
Any ideas how to do this?
Thanks.
We can't use view formatting for the default Tiles style view, we need create following view formatting for List style view.
{
"schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
"hideSelection": "true",
"hideColumnHeader": "true",
"rowFormatter": {
"elmType": "a",
"attributes": {
"href": "[$FileRef]",
"target": "'_blank'"
},
"style": {
"float": "left"
},
"children": [
{
"elmType": "div",
"attributes": {
"class": "ms-bgColor-themeLighterAlt ms-bgColor-themePrimary--hover ms-fontColor-white--hover"
},
"style": {
"display": "flex",
"flex-wrap": "wrap",
"min-width": "180px",
"min-height": "150px",
"margin-right": "10px",
"margin-top": "10px",
"box-shadow": "2px 2px 4px darkgrey"
},
"children": [
{
"elmType": "div",
"style": {
"text-align": "center",
"margin": "auto"
},
"children": [
{
"elmType": "div",
"attributes": {
"class": "sp-row-title "
},
"txtContent": "[$Title]"
},
{
"elmType": "div",
"attributes": {
"iconName": "Test",
"class": "ms-fontSize-su"
}
}
]
}
]
}
]
}
}
Refer to: sp-dev-list-formatting>generic-tile-format