0

enter image description hereenter image description here

Hi I have a cascading lookup column in sharepoint modern view. That column is redering as html.I am new to column formatting and when i use this code it converts the whole html into link. What i want is it should only take the lookup value and show it as a link. Please refer to the image below.

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
   "elmType": "a",
   "txtContent": "@currentField",
   "attributes": {
      "target": "_blank",
      "href": "='www.google.com' + @currentField"
   }
}

enter image description here

0

Lookup fields are also represented as objects; the display text is stored in the lookupValue property. As I am not sure about your list setup so only suggestions based on assumption. First try with @currentField.lookupValue instead of @currentField, if the look up field has value of part of the URL and you are trying to rebuild a full URL. More information about your list will be helpful.

Update: Try with the json below:

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
   "elmType": "div",
   "txtContent": "@currentField.lookupValue"
}
9
  • Hi thanks for quick reply i have tried using @currentField.lookupValue but then the whole column appears as blank . The two fields shown in the image are cascading looup columns and its a customized form so the code is working fine in classic sharepoint pages but its is rendering as markup in modern sites. I have attached list schema . Feb 1 at 6:12
  • @nehagharpure. OK I see you problem. JSON formatting simply works for modern experience. And if you are using script to modify the column value in the form in classic experience, I am not sure it will work as you want (in modern experience) to change the formatting of the customized field.
    – Jerry_MSFT
    Feb 1 at 6:18
  • @nehagharpure. So if the cascading lookup works fine for you, I will suggest keeping on the code way to customize. Modern experience does not support script editor to customize. If you still try to work with JSON formatting, you may need another way to create the cascade dropdown, like using PowerApps.
    – Jerry_MSFT
    Feb 1 at 6:20
  • I am trying to edit in modern view only. But the thing is that i dont know how to fetch the lookup column value displayed in between the anchor tags. Is there any way i can get those value. Since i am new to column formatting i dont know how to work with loop index or for each loop . Feb 1 at 6:24
  • One thing I would like to confirm. In you new screenshot, I find that two columns are "Cascading Dropdown" Field. As in SharePoint Online, we do not have such column type, I would like to know if you are using some 3rd party tools. JSON formatting supports lookup column. The lookup column object simply has ID and value, by default @currentField.lookupValue or [$FieldName.lookupValue] shall both works. Please have a try with the test JSON I updated in the reply. If it still goes blank, it may be a bit more complex.
    – Jerry_MSFT
    Feb 1 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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