I have a multiple lookup data inside a table. I have to format a text "Stato" with green background if it is "PRONTO CONSEGNA".

enter image description here

And do the same thing inside the table isolating the single "Id_uni" and not the whole cell.

Is there a way to do that?

enter image description here


Format a text "Stato" with green background if it is "PRONTO CONSEGNA":

Edit the DispForm.aspx and add a Script Editor web part, enter the following scripts into the web part, then save the page.

<script type="text/javascript" src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
function ready(){
                var oFieldValue = $('td.ms-formlabel:contains("Stato")').closest('td').next('td');                          
                // use trim() function to remove the whitespace from the beginning and end of a string
               var fieldValue = oFieldValue.text().trim();
                if(fieldValue == 'PRONTO CONSEGNA'){
                                 oFieldValue.css("background-color", "green"); 

Testing result:

enter image description here

Format single "Id_Uni" in lookup column based on "Stato" in modern list:

The lookup field object has two properties: lookupId and lookupValue. You are getting "Id_uni" as the lookup value. It cannot get the "Stato" from the lookup in JSON column formatting. In modern view, we cannot format the single "Id_Uni" in a lookup column which has multiple values. And there is now method to use scripts to a modern list.

As a workaround, you can back to classic view and use CSR to render the lookup field in the list based on the "Stato".


Currently, there is not function to split string based on the semicolon or iterate lookup values when using json column formatting.

Learn more about json formatting

| improve this answer | |

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.