SOLVED

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

%3CLINGO-SUB%20id%3D%22lingo-sub-2275257%22%20slang%3D%22en-US%22%3EUsing%20JSON%20to%20Show%2FHide%20Modern%20Form%20Field%20Based%20on%20Value%20Selected%20in%20Lookup%20Column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2275257%22%20slang%3D%22en-US%22%3E%3CDIV%20class%3D%22votecell%20post-layout--left%22%3E%3CDIV%20class%3D%22js-voting-container%20grid%20jc-center%20fd-column%20ai-stretch%20gs4%20fc-black-200%22%3E%3CSPAN%3EI%20am%20trying%20to%20modify%20the%20new-entry%20form%20of%20a%20modern%20list%20in%20SharePoint%20Online%20by%20hiding%20or%20showing%20a%20field%20based%20on%20the%20value%20selected%20in%20a%20preceding%20field%20on%20the%20same%20form.%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fdeclarative-customization%2Flist-form-conditional-show-hide%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EMicrosoft%20offers%20straightforward%20guidance%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Eon%20how%20to%20do%20this%20using%20a%20JSON%20snippet.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22js-voting-container%20grid%20jc-center%20fd-column%20ai-stretch%20gs4%20fc-black-200%22%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%20class%3D%22postcell%20post-layout--right%22%3E%3CDIV%20class%3D%22s-prose%20js-post-body%22%3E%3CP%3EWhile%20the%20article%20doesn't%20list%20a%20lookup%20column%20as%20an%20unsupported%20field%20type%20to%20use%20for%20this%20purpose%2C%20it%20doesn't%20provide%20guidance%20on%20how%20to%20use%20one%20in%20this%20way%2C%20either.%20From%20my%20testing%2C%20you%20can't%20simply%20grab%20the%20value%20of%20a%20lookup%20field%20in%20the%20described%20way%3A%3C%2FP%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%3Dif(%5B%24LookupField%5D%3D%3D'Hourly'%2C%20'true'%2C%20'false')%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20use%20a%20%3CEM%3Echoice%3C%2FEM%3E%20field%20instead%20of%20a%20lookup%20field%2C%20this%20works%20fine.%20But%20since%20I've%20got%20a%20lookup%20field%2C%20I%20did%20some%20more%20digging%2C%20and%20in%20some%20other%20contexts%20it%20looks%20like%20the%20value%20may%20be%20captured%20in%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3ElookupValue%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eproperty%2C%20so%20I%20tried%20it%20this%20way%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%3Dif(%5B%24LookupField.lookupValue%5D%3D%3D'Hourly'%2C%20'true'%2C%20'false')%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20it%20doesn't%20work.%20Elsewhere%20someone%20said%20that%20by%20doing%20some%20debugging%2C%20it%20looks%20like%20the%20function%20is%20expecting%20this%20construction%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%3Dif(%5B%24LookupField%5D%3D%3D'1%3B%23Hourly'%2C%20'true'%2C%20'false')%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENo%20errors%2C%20but%20still%20no%20luck.%20Does%20anyone%20know%20if%20it%20is%20possible%20to%20use%20the%20value%20from%20a%20lookup%20field%20in%20this%20way%3F%20And%20how%20would%20I%20do%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2275257%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ELists%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New Contributor
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?

5 Replies
best response confirmed by Aylarja (New Contributor)
Solution

@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.

@ganeshsanap, thanks for responding to my question here as well as on StackExchange. Unfortunately, your answer didn't change from "no" to "yes" in between! :smile: But everything I see confirms what you say: currently, it isn't possible to use the value of a Lookup field in this way. For anyone interested in this capability, I have created a UserVoice request for it

@Aylarja You're welcome!

 

Thanks for creating a UserVoice for this. But looks like the link to UserVoice is broken/wrong in your above reply.

So, I am adding the correct link below for anyone who wants to vote on your idea (I already voted!):

Enable the ability to hide SharePoint form fields based on the value of Lookup columns  

 

Also, I have updated the documentation at: Show or hide columns in a list or library form 


Please click Like if my post was useful to you in any way.

Thank you, @ganeshsanap , for correcting the UserVoice link. I have since edited my comment to correct the bad link.

 

I see that you updated the Microsoft article on this matter to include Lookup fields as not supporting the described behavior. You might be interested that there is a user comment on GitHub related to that article that suggests that the Lookup field can be used in this way. In my testing, the approach suggested there did not work, but I am interested in seeing if others find the author's recommendation works.

@Aylarja I did lot of other updates to the article along with adding lookup as not supported column.

 

Also, I tried the approach suggested by Denis to use ItemID;#ColumnValue. But it didn't work for me as well.

Even I saw the below message in browser's developer console when I tried to use the lookup column in conditional formula (Might be because there was no value on list form for the lookup column):

 

ganeshsanap_0-1618594447241.png


Please click Like if my post was useful to you in any way.