Forum Discussion

Aylarja's avatar
Aylarja
Copper Contributor
Apr 15, 2021
Solved

Using JSON to Show/Hide Modern Form Field Based on Value Selected in Lookup Column

I am trying to modify the new-entry form of a modern list in SharePoint Online by hiding or showing a field based on the value selected in a preceding field on the same form. Microsoft offers straightforward guidance on how to do this using a JSON snippet.
 

While the article doesn't list a lookup column as an unsupported field type to use for this purpose, it doesn't provide guidance on how to use one in this way, either. From my testing, you can't simply grab the value of a lookup field in the described way:

 

 

=if([$LookupField]=='Hourly', 'true', 'false')

 

 

If I use a choice field instead of a lookup field, this works fine. But since I've got a lookup field, I did some more digging, and in some other contexts it looks like the value may be captured in a lookupValue property, so I tried it this way:

 

 

=if([$LookupField.lookupValue]=='Hourly', 'true', 'false')

 

 

But it doesn't work. Elsewhere someone said that by doing some debugging, it looks like the function is expecting this construction:

 

 

=if([$LookupField]=='1;#Hourly', 'true', 'false')

 

 

No errors, but still no luck. Does anyone know if it is possible to use the value from a lookup field in this way? And how would I do this?

  • Aylarja 

    Lookup fields are not supported in conditional formulas in SharePoint.

     

    Source: can we show a column in a form based on a lookup field?


    Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

Resources