Is this piece of code correct?

Hello everyone! I inserted this piece of code into one of my files and it works of course as I found the code here, but I’m not sure it’s the right one because the link is old. Could you, please, help me on this point? Thank you! This is my code:

if($Type="Livre") {$Color="poppy"};if($Type="Article") {$Color="red"};
if($Type="Communication") {$Color="green"};

Hi Dominique,

One error I see is with your if statements. You have if($Type=“Something” // rather than more correctly if($Type==“Something”

if($Type==“Livre”) {$Color=“poppy”};
if($Type==“Article”) {$Color=“red”};
if($Type==“Communication”) {$Color=“green”};

Is more correct

1 Like

This is a valid action.

Is it what you want? Perhaps! Books will be poppy-colored, articles will be red, and communications will be green.

One common issue with these sort of action is: what happens if a note was once an Article, but stops being one? If its $Type becomes empty (or if it becomes “Retracted Article” or “Chapter”), it will remain red because the action sets the colors of types it recognizes, but does nothing for types it doesn’t recognize.

A small change would address this:

if($Type=="Livre") {$Color="poppy"};
if($Type=="Article") {$Color="red"};
if($Type=="Communication") {$Color="green"};

Each time this runs, the color is reset to whatever color the note inherits, or to the default color. Then, if we recognize the type, we set the color again.

This is neither better nor worse than the original design: it’s different.