Forum Discussion

avytrykh's avatar
avytrykh
Copper Contributor
Jul 15, 2021
Solved

Use lookup value in column formatting.

Hi community

I have format of the column Accept docs like below:

	  {
  "$schema": "https: //developer.microsoft.com/en-us/json-schemas/sp/column-formatting.schema.json",
  "elmType": "span",
  "children": [
    {
      "elmType": "span",
      "txtContent": "=if(@currentField == true, 'Yes', if(@currentField == false, 'No', ''))"
    },
    {
      "elmType": "button",
      "txtContent": "Accept",
      "customRowAction": {
        "action": "executeFlow",
        "actionParams": "{\"id\": \"\"}"
      },
      "style": {
        "border": "none",
        "background-color": "#2ca1e8",
        "color": "white",
        "visibility": "=if([$Country.lookupValue] == 'India', 'hidden',  'visible')",
        "padding": "0 15%",
        "display": "flex",
        "margin-left": "10%",
        "cursor": "pointer"
      }
    }
  ]


Country is a column with Lookup type.
I want to set visibility value depends on Country lookup value.

I tried this simple if condition,. but it is not work for me.
Any suggestions?

  • avytrykh you've got an elm type of span AND an elm type of button both operating on the same item. That's the main cause of your problem; I would remove that span with the if currentfield txtcontent. The following will work (change flow ID and the column name to yours):

    	{
      "$schema": "https: //developer.microsoft.com/en-us/json-schemas/sp/column-formatting.schema.json",
          "elmType": "button",
          "txtContent": "Accept",
          "customRowAction": {
            "action": "executeFlow",
            "actionParams": "{\"id\":\"0eb7e84b-4158-47b0-b19e-aff0aa26af3d\", \"headerText\":\"Sign Off\",\"runFlowButtonText\":\"Request Sign Off\"}"
      },
          "style": {
            "background-color": "#2ca1e8",
            "color": "white",
            "visibility": "=if([$Project.lookupValue] == 'G-HERC', 'visible',  'hidden')"
    
          }
        }

     

    Rob
    Los Gallardos
    Intranet, SharePoint, Website and Power Platform Manager (and classic 1967 Morris Traveller driver)

  • RobElliott's avatar
    RobElliott
    Silver Contributor

    avytrykh you've got an elm type of span AND an elm type of button both operating on the same item. That's the main cause of your problem; I would remove that span with the if currentfield txtcontent. The following will work (change flow ID and the column name to yours):

    	{
      "$schema": "https: //developer.microsoft.com/en-us/json-schemas/sp/column-formatting.schema.json",
          "elmType": "button",
          "txtContent": "Accept",
          "customRowAction": {
            "action": "executeFlow",
            "actionParams": "{\"id\":\"0eb7e84b-4158-47b0-b19e-aff0aa26af3d\", \"headerText\":\"Sign Off\",\"runFlowButtonText\":\"Request Sign Off\"}"
      },
          "style": {
            "background-color": "#2ca1e8",
            "color": "white",
            "visibility": "=if([$Project.lookupValue] == 'G-HERC', 'visible',  'hidden')"
    
          }
        }

     

    Rob
    Los Gallardos
    Intranet, SharePoint, Website and Power Platform Manager (and classic 1967 Morris Traveller driver)

Resources