1

I have a lookup (choice) column - Work Location - I would like another column - logo - to pull from an image library depending on what choice was given in Work Location.

After some research, I came up with the following:

{  
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",  
  "elmType": "img",  
  "style": {  
    "width": "100px"  
  },  
  "attributes": {  
   "src": "=if([Work_x0020_Location] == ‘Main Office', 'https://argenttechnet.sharepoint.com/:i:/s/HR/EVrDuspyW7VHrbdro8qIyfUB-zJmvTfRs6mt4UCHS8oMgQ?e=JxjhDx', if([Work_x0020_Location]  == ‘Remote/Home', 'https://argenttechnet.sharepoint.com/:i:/s/HR/EWzUpzmEPrZOm5QlGcmImfEB8x7bl7GEBEhWGuh-r1eTrQ?e=dhrUOM', if([Work_x0020_Location] == ‘DOD Installation', 'https://argenttechnet.sharepoint.com/:i:/s/HR/EZmme3yMtitAh52a-RG8TbABJZ4TpmlIstVVKz7WoaurZQ?e=mhxtbX',if([Work_x0020_Location] == ‘VA Facility’,’https://argenttechnet.sharepoint.com/:i:/s/HR/EWTh90hhj51NjOOMZf2PO1sBADYszr_YqivKfMcB_WwULw?e=gZNC2j','https://xxxx.sharepoint.com/sites/echodu/SiteAssets/icon/na.jpg', if([Work_x0020_Location] == ‘Indian Health Service', ‘https://argenttechnet.sharepoint.com/:i:/s/HR/EcczRDIKTsdMqLhCD4LPErYByTy9e-P-ZH1oigwzGrjPAg?e=0hBOYA', if([Work_x0020_Location] == ‘US Government', ‘https://argenttechnet.sharepoint.com/:i:/s/HR/EWTh90hhj51NjOOMZf2PO1sBADYszr_YqivKfMcB_WwULw?e=gZNC2j',)))))"  
  }  
}

I also tried:

{  
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",  
  "elmType": "img",  
  "style": {  
    "width": "100px"  
  },  
  "attributes": {  
   "src": "=if(@Work_x0020_Location.lookupValue == ‘Main Office', 'https://argenttechnet.sharepoint.com/:i:/s/HR/EVrDuspyW7VHrbdro8qIyfUB-zJmvTfRs6mt4UCHS8oMgQ?e=JxjhDx', if(@Work_x0020_Location.lookupValue  == ‘Remote/Home', 'https://argenttechnet.sharepoint.com/:i:/s/HR/EWzUpzmEPrZOm5QlGcmImfEB8x7bl7GEBEhWGuh-r1eTrQ?e=dhrUOM', if(@Work_x0020_Location.lookupValue == ‘DOD Installation', 'https://argenttechnet.sharepoint.com/:i:/s/HR/EZmme3yMtitAh52a-RG8TbABJZ4TpmlIstVVKz7WoaurZQ?e=mhxtbX',if(@Work_x0020_Location.lookupValue == ‘VA Facility’,’https://argenttechnet.sharepoint.com/:i:/s/HR/EWTh90hhj51NjOOMZf2PO1sBADYszr_YqivKfMcB_WwULw?e=gZNC2j','https://xxxx.sharepoint.com/sites/echodu/SiteAssets/icon/na.jpg', if(@Work_x0020_Location.lookupValue == ‘Indian Health Service', ‘https://argenttechnet.sharepoint.com/:i:/s/HR/EcczRDIKTsdMqLhCD4LPErYByTy9e-P-ZH1oigwzGrjPAg?e=0hBOYA', if(@Work_x0020_Location.lookupValue == ‘US Government', ‘https://argenttechnet.sharepoint.com/:i:/s/HR/EWTh90hhj51NjOOMZf2PO1sBADYszr_YqivKfMcB_WwULw?e=gZNC2j',)))))"  
  }  
}

I ran both through JSON checker and found no syntax errors. What am I doing wrong?

1
  • Hi, did you try suggestions in my answer below? Is it working for you now? Commented Mar 2, 2023 at 8:14

1 Answer 1

0
  1. You have to use the correct internal name of column in this format: [$InternalNameOfColumn]. So, use: [$Work_x0020_Location] at all places
  2. Make sure you are using correct image URL in this format: https://tenant.sharepoint.com/sites/siteName/libraryName/folderName/na.jpg'. Follow steps given here to find the URL in above format: How can I show a subfolder from another SharePoint site?

Use JSON like:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "img",
  "style": {
    "width": "100px"
  },
  "attributes": {
    "src": "=if([$Work_x0020_Location] == 'Main Office', 'https://argenttechnet.sharepoint.com/:i:/s/HR/EVrDuspyW7VHrbdro8qIyfUB-zJmvTfRs6mt4UCHS8oMgQ?e=JxjhDx', if([$Work_x0020_Location]  == 'Remote/Home', 'https://argenttechnet.sharepoint.com/:i:/s/HR/EWzUpzmEPrZOm5QlGcmImfEB8x7bl7GEBEhWGuh-r1eTrQ?e=dhrUOM', if([$Work_x0020_Location] == 'DOD Installation', 'https://argenttechnet.sharepoint.com/:i:/s/HR/EZmme3yMtitAh52a-RG8TbABJZ4TpmlIstVVKz7WoaurZQ?e=mhxtbX', if([$Work_x0020_Location] == 'VA Facility', 'https://argenttechnet.sharepoint.com/:i:/s/HR/EWTh90hhj51NjOOMZf2PO1sBADYszr_YqivKfMcB_WwULw?e=gZNC2j', if([$Work_x0020_Location] == 'Indian Health Service', 'https://argenttechnet.sharepoint.com/:i:/s/HR/EcczRDIKTsdMqLhCD4LPErYByTy9e-P-ZH1oigwzGrjPAg?e=0hBOYA', if([$Work_x0020_Location] == 'US Government', 'https://argenttechnet.sharepoint.com/:i:/s/HR/EWTh90hhj51NjOOMZf2PO1sBADYszr_YqivKfMcB_WwULw?e=gZNC2j', 'https://xxxx.sharepoint.com/sites/echodu/SiteAssets/icon/na.jpg'))))))"
  }
}

Documentations:

  1. SharePoint Column formatting

  2. How to find the Internal name of columns in SharePoint Online?

5
  • I used the JSON you posted - but changed all the URLs to the format you suggested. When I leave your code in tact, it fills [$logo] with the broken image icon in the final line of your JSON, no matter which choice is selected. When I remove the na.jpg line, it leaves [$logo] empty. I cannot get it to pull the correct image (or any image other than na.jpg) based on the choice made in [$Work_x0020_Location] Commented Mar 2, 2023 at 15:52
  • Make sure you have shown/included work location column in list view. This is required to use the column in json formatting. Commented Mar 2, 2023 at 17:34
  • Yes, Work Location is included in the list view. Commented Mar 3, 2023 at 16:12
  • Got it. Changed to pulling based on WorkLocationID # instead of text. Working code: ..."src": "=if([$Work_x0020_Location_x003a_ID] == '1', 'argenttechnet.sharepoint.com/sites/Hr/Images1/WLT/AT_icon.png',... Commented Mar 3, 2023 at 17:15
  • Great, glad it worked for you! Commented Mar 3, 2023 at 18:35

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.