Home > OS >  How do I create an if statement in a sharepoint list that checks if in column "name" you c
How do I create an if statement in a sharepoint list that checks if in column "name" you c

Time:12-08

I currently started working with Sharepoint and need to create a list the involves personal information (Name, Surname, Description, ...). Maybe some background to what I want to do.

For filtering purpose I have added a dummy line that has all those fields filled with "!". In my last column I want to create a button that allows me to trigger a PowerAutomate flow in order to copy all mails. Now this is were I am stuck. This button I want to create should only be available in the dummy line, where e.g. the field name is filled with "!" but so far I only managed to display my button in all rows and not just the dummy row. I thought about creating an if-statement that checks the field/column "name" for "!" and if that is the case, I want to create the button, but since I am quite new to Sharepoint/JSON I have trouble figuring out what is the exact problem and why my code is not working.

So far I tried to find a solution for my problem, but only came up with this here, which is not quite working. I would really appreciate some help. Thank you very much in advance guys! :)

Edit: A link to the picture for my sharepoint list is below the code :)

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",

  "if" : {
    "name" : "!" 
  },
  "then" : [
    {
      "txtContent": "Copy",
      "attributes": {
      "href": "='Here the link to my PowerAutomate-Flow will be pasted'"}
    }
  ],
  "else" : [
    {
      "txtContent": "",
      "attributes":{
      "href": "=''"}
    }
  ],


  "style": {
    "padding": "0px 25px",
    "cursor": "pointer",
    "border": "none",
    "color": "white",
    "font-weight": "550",
    "background-color": "#0078d4",
    "text-decoration": "none",
    "font-size": "14px",
    "text-align": "center",
    "width": "35px"
  }
}

[My Sharepoint-List](https://i.stack.imgur.com/Dj7RK.png)

CodePudding user response:

Here is a similar case for you to refer to: https://learn.microsoft.com/en-us/answers/questions/737561/displaynot-dispaly-through-fromat-column-in-sharep.html?childToView=737760#answer-737760

In this case, if the status column is equal to 'Closed', then the button will not work. If not, there will be a button to trigger a flow.

As the button you want to create should only be available in the dummy line, where e.g. the field name is filled with "!", you could modify the code like this:

 {
   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
   "elmType": "div",
   "children": [
     {
       "elmType": "button",
       "customRowAction": {
         "action": "executeFlow",
         "actionParams": "{\"id\": \"386b81a1-fce2-45da-a981-91160d0d9245\"}"
       },
       "attributes": {
         "class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"
       },
       "txtContent": "copy",
       "style": {
          "border": "none",
          "background-color": "lightgreen",
          "cursor": "pointer",
          "display": "=if([$name]=='!','inherit','none')"
       }
     },
     {
       "elmType": "span",
       "style": {
         "padding-right": "8px",
         "display": "=if([$name]=='!','none','inherit')"
       },
       "txtContent": "@currentField"
     }
   ]
 }

You could change the parameter in the code according to your own requirement, for example: the "actionParams": "{"id": "386b81a1-fce2-45da-a981-91160d0d9245"}" is generated by the flow I created, you need to change it into your own flow id.

  • Related