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


Thank you so much this work! I can try to add a column "Stato" near "Id_uni" but the problem is that the "Stato" have "inline-results" like this separated by ;

enter image description here

It could be great if is there a way to get result vertically line by line and format it like:

if there is a "text" different from "PRONTO CONSEGNA" (nok status) red-background else green backgorund.

I'm so sorry but I'm not a dev :)

  • No, it is impossible in the modern list. Currently, there is not function to split string based on the semicolon or iterate lookup values when using json column formatting.(I have updated my answer.) If my answer is useful, please don't forget to accept it as the best answer. Thanks. – JoannaW_MSFT Mar 6 at 10:48

I don't want to use semicolon, I just want to create 2 column first near second and load results like this:

enter image description here

But the main problem is that "Stato" column have a inline and not like-break format

  • You can refer to blog.vitalyzhukov.ru/en/…. By the way, you can edit your original post and put the update content into it or add comment instead of "Add Answer". – JoannaW_MSFT Mar 7 at 2:40
  • I just look into this website but there are no information about "line-break" after ; on a lookup. – MarkR Mar 7 at 15:33

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.