Forum Discussion
Pb with formating column
Hello, 🙂
I would like to format a column in a list.
This column displays the name of a person in our AD along with their email address. I found the JSON code in this community.
When the column doesn't correspond to an AD user, I would like to display text located in another column.
To do this, I included a condition in the code. But it doesn't work. The field remains empty when the person is not associated with the column.
The portion of code that is probably problematic :
"txtContent": "=if([$person.title] == '', [$FullName], [$person.title])"
$FullName is the name of an other column :
{
"CellPhone": "XX XX XX XX XX",
"ContentType": "Contact",
"ContentTypeId": "0x01060062E91085FE5F6C468F33BBF1D871B1F7",
"FileRef": "/sites/dsnb/it/Lists/Phones/1_.000",
"FirstName": "",
"FolderChildCount": "0",
"FSObjType": "0",
"FullName": "SERVICE 01",
"ID": "1",
"ItemChildCount": "0",
"PermMask": "0x7ffeffffffffffff",
"SMTotalSize": "236",
"WorkPhone": ""
},
{
"CellPhone": "YY YY YY YY YY",
"ContentType": "Contact",
"ContentTypeId": "0x01060062E91085FE5F6C468F33BBF1D871B1F7",
"FileRef": "/sites/dsnb/it/Lists/Phones/2_.000",
"FirstName": "Toto",
"FolderChildCount": "0",
"FSObjType": "0",
"FullName": "SERVICE 02",
"ID": "2",
"ItemChildCount": "0",
"PermMask": "0x7ffeffffffffffff",
"SMTotalSize": "296",
"WorkPhone": "AA AA AA AA AA"
}Could you please help me with this?
Thank you in advance.
Ci-dessous le code JSON :
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"children": [
{
"elmType": "div",
"style": {
"background-color": "=if(length(@currentField) == 0, '#ddd', '#aaa'",
"border-radius": "1.5em",
"color": "white",
"height": "1.5em",
"min-width": "1.5em",
"position": "absolute",
"right": "1em",
"text-align": "center",
"top": "0"
},
"txtContent": "=length(@currentField)"
},
{
"children": [
{
"children": [
{
"attributes": {
"href": "='mailto:' + [$person.email]"
},
"children": [
{
"elmType": "div",
"style": {
"font-size": "1.2em"
},
"txtContent": "=if([$person.title] == '', [$Fullname], [$person.title])"
},
{
"elmType": "div",
"style": {
"color": "gray"
},
"txtContent": "[$person.email]"
}
],
"elmType": "a",
"style": {
"margin-left": "0.5em"
}
}
],
"elmType": "div",
"style": {
"display": "flex",
"flex-direction": "row",
"justify-content": "center"
}
}
],
"elmType": "div",
"forEach": "person in @currentField",
"style": {
"justify-content": "center",
"margin-top": "=if(loopIndex('person') == 0, '0', '1em')"
}
}
],
"elmType": "div",
"style": {
"align-items": "start",
"flex-direction": "column",
"min-height": "1.5em"
}
}
2 Replies
- grant_jenkinsIron Contributor
Is your [$FullName] column added (visible) in the current View? If not, then it won't be able to reference it which might be the reason you are getting blank values.
To test, can you try the following to see if you see the static text:
"txtContent": "=if([$person. Title] == '', 'TESTING', [$person. Title])"- FabienGUILLAUMECopper Contributor
Hello,
Thank you for your help.
It works fine now.
Sincerely,