How to apply the lookup value when formatting the column by JSON

Li, York 61 Reputation points
2023-05-05T09:44:56.41+00:00

Hi Guys:

  I have a list with lookup value, the lookup source is product name, the lookup value is the column "Product Name:Mic Assembly", and if the Inspection Type is "Mic Assembly", I hope the Workstaion Qty will be "9" as shown in the "Product Name:Mic Assembly" column. 

  But the expression below can't get the value, could you help check the reason? "[$ProductName:MicAssembly.lookupValue]" may be a mistake, but I don't know how to correct it.

User's image

Microsoft 365 and Office | SharePoint | For business | Windows
{count} votes

Accepted answer
  1. Emily Du-MSFT 51,846 Reputation points Microsoft External Staff
    2023-05-08T08:00:07.1366667+00:00

    Please use following formula in the JSON formatting.

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      "elmType": "div",
      "txtContent": "=if([$InspectionType] == 'Mic Assembly', '[$Product_x0020_Name_x003a__x0020_]', 'NO')"
    }
    

    Result:

    User's image


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Tuncel Biyikli 40 Reputation points
    2024-08-14T07:46:01.6133333+00:00

    Hi, ich have a similar problem! The conditional formatting should reference a choice field. If the cell is empty ("") and the column 'Equipmenttyp' has the value 'Example Device', the cell should be red. I tried also with "lookupvalue" and "value", but is not working :

    {

    "elmType": "div",

    "style": {

    "background-color": "=if(and([$Equipmenttyp] == 'Example Device', @currentField == ''), '#FFC7CE', '')"
    

    },

    "children": [

    {
    
      "elmType": "span",
    
      "txtContent": "@currentField"
    
    }
    

    ]

    }


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.