Forum Discussion
SharePoint List button not working!
Hi all, I have a Property Key Check In/Out list and trying to include a button to auto populate the fields. Using the JSON below, but it isn't working. I've isolated the Status field and that works, but the Person and Date & Time keeps erroring. I checked and double-checked the column settings and the JSON is using the correct Internal names, and the columns are correctly set up to one person only and date and time, and not required. Copilot (you'll be surprised) is absolutely no help.
I also tried replacing "null" with '' but still not working.
Here's the JSON;
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "button",
"style": {
"padding": "6px 12px",
"border-radius": "6px",
"border": "1px solid",
"cursor": "pointer",
"font-weight": 600,
"background-color": "=if([$Status] == 'IN', '#107c10', '#d83b01')",
"border-color": "=if([$Status] == 'IN', '#0b6a0b', '#be3700')",
"color": "white"
},
"attributes": {
"title": "=if([$Status] == 'IN', 'Check this key OUT', 'Check this key IN')",
"aria-label": "=if([$Status] == 'IN', 'Check this key OUT', 'Check this key IN')"
},
"txtContent": "=if([$Status] == 'IN', 'Check Out', 'Check In')",
"customRowAction": {
"action": "setValue",
"actionInput": {
"Status": "=if([$Status] == 'IN', 'OUT', 'IN')",
"CheckedOutByColleague": "=if([$Status] == 'IN', me, null)",
"WhenCheckedOut": "=if([$Status] == 'IN', @now, null)"
}
}
}
2 Replies
- SupernovaBrass Contributor
Unfortunately, column formatting JSON cannot set Person or DateTime fields dynamically. Microsoft only allows setValue for Text, Choice, Number, Yes/No fields.
>>That’s why your Status field works fine, but the Person and DateTime ones fail.
Think of JSON column formatting like a paintbrush — it can change how things look and do simple actions (like flipping a switch). But it can’t write complex values like people or timestamps. For those, you need a toolbox (Power Automate or Power Apps) that can handle more advanced logic.
your JSON is fine for Status, but you’ll need Power Automate or Power Apps to populate Person and DateTime.
Power Automate flow that will handle the Person and DateTime fields whenever your JSON button flips the Status column. This way, you keep the button simple (just toggling IN/OUT), and let the flow fill in the rest.Flow Setup
- Trigger
- Go to Power Automate → Create → Automated cloud flow.
- Choose trigger: When an item is created or modified (SharePoint).
- Select your site and the Property Key Check In/Out list.
- Condition
- Add a Condition action:
- If Status equals OUT → then we know the key was checked out.
- Else → it was checked in.
- Add a Condition action:
- Update Item
- In the Yes branch (Status = OUT):
- Add Update item action.
- Set:
- CheckedOutByColleague → Modified By (dynamic content).
- WhenCheckedOut → utcNow() (use an expression).
- In the No branch (Status = IN):
- Add Update item action.
- Set:
- CheckedOutByColleague → leave blank (or clear field).
- WhenCheckedOut → leave blank.
- In the Yes branch (Status = OUT):
- Save & Test
- Save the flow.
- Go back to your list, click the JSON button to toggle Status.
- Flow will run and auto‑populate the Person and DateTime fields.
🤖 If my post solved your issue or answered your query, please mark it as a Solution and give it a Like.
- Trigger
- virendrakIron Contributor
For setValue in column formatting, a single‑select Person field actually expects the person token directly, not an object.
For a single‑person field, this is the correct pattern:
"CheckedOutByColleague": "=if([$Status] == 'IN', , '')"After several iterations and guidance from Copilot, I was finally able to produce the correct working JSON.
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "button", "style": { "padding": "6px 12px", "border-radius": "6px", "border": "1px solid", "cursor": "pointer", "font-weight": 600, "background-color": "=if([$Status] == 'IN', '#107c10', '#d83b01')", "border-color": "=if([$Status] == 'IN', '#0b6a0b', '#be3700')", "color": "white" }, "attributes": { "title": "=if([$Status] == 'IN', 'Check this key OUT', 'Check this key IN')", "aria-label": "=if([$Status] == 'IN', 'Check this key OUT', 'Check this key IN')" }, "txtContent": "=if([$Status] == 'IN', 'Check Out', 'Check In')", "customRowAction": { "action": "setValue", "actionInput": { "Status": "=if([$Status] == 'IN', 'OUT', 'IN')", "CheckedOutByColleague": "=if([$Status] == 'IN', , '')", "WhenCheckedOut": "=if([$Status] == 'IN', @now, '')" } } }If my post solved your issue or answered your query, please mark it as a Solution and give it a Like.