0

We are using "Column Formatting" option on SP document library for particular column. When it folder, then that option need to hide, if it file or document inside the folder, then option need to visible. Below json code i am trying but its is hiding option for both file and folder. Can anyone suggest us with correct code line.

Screenshot

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "button",
  "customRowAction": {
    "action": "executeFlow",
    "actionParams": "{\"id\": \"\"}"
  },
  "attributes": {
    "class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"
  },
  "style": {
    "border": "none",
    "cursor": "pointer",
    "background-color": "#D5D5D5",
    "color": "#000",
    "padding": "4px 4px 4px 10px",
    "border-radius": "5px",
    "display": "=if([$ItemType]=='Folder', 'none', 'inherit')"
  },
  "children": [
    {
      "elmType": "span",
      "txtContent": "Request approval"
    }
  ]
}
1
  • Instead of [$ItemType] use [$ContentType]. Also, make sure you have shown/included content type column in the library view. Let me know if this works for you. Commented Jun 26, 2023 at 4:54

1 Answer 1

0

You can use FSObjType field to decide whether it's folder or document. If it's value is 0 then it's document and it it's value is 1 then it's folder. See official documentation here

You can use following JSON which should give correct output which you want:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "button",
  "customRowAction": {
    "action": "executeFlow",
    "actionParams": "{\"id\":\"{flowID}\"}"
  },
  "attributes": {
    "class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"
  },
  "style": {
    "border": "none",
    "cursor": "pointer",
    "background-color": "#D5D5D5",
    "color": "#000",
    "padding": "4px 4px 4px 10px",
    "border-radius": "5px",
    "display": "=if(  ([$FSObjType] == '0' ), 'block', 'none')"
  },
  "children": [
    {
      "elmType": "span",
      "txtContent": "Request Approval"
    }
  ]
}

See output below:

enter image description here

2
  • would you please provide us with an update on the status of your issue? Commented Jul 3, 2023 at 5:56
  • @RaytheonXie-MSFT I am not sure to whom you are asking? are you asking me or to author of this question? Commented Jul 3, 2023 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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