INTERACT FORUM
More => Old Versions => Media Center 17 => Topic started by: Otello on January 24, 2012, 09:49:35 am
-
Can somebody help me writing an expression?
I made a "static" expression for the titles of classical music view:
[Composer] - [Album] By [Conductor], [Artist], [Orchestra] - [Date]
It works with a piano concerto, where all the fields are filled, but for instance with a Piano Sonata without Date I get something like:
Beethoven - Piano Sonata No.29 Op.106 By , Pollini, -
(please note the unwanted commas and "-" at the end.)
I'd like to have listed, comma separated, the not empty [Conductor], [Artist] and [Orchestra] fields and avoid the endind "-" in case the Date is empty.
I imagine it's quite trivial, but I'm always been thick in scripting. ;)
Thanks.
-
You could use If expressions.
http://wiki.jriver.com/index.php/Media_Center_expression_language#If.28....29:_Conditional_If.2FThen.2FElse_evaluator.
Shouldn't be an issue if you have some scripting experience.
-
Shouldn't be an issue if you have some scripting experience.
Ehm... ;D
I'm always been thick in scripting.
-
Does this work?
[Composer] - [Album] By [Conductor], [Artist], [Orchestra] If(IsEmpty([Date]),,- [Date])
-
It works 50%.
i.e.: it cured the "-" but not the unwanted commas.
Thanks for the help, anyway.
-
Ok, then you need to make similar checking for every field (or maybe use that IfElse structure). I need to go now so I can't make the expression for you right now but I can help later if someone else hasn't by the time I available again.
-
lepa has it right.
Artist, for example, might look like this.
If(IsEmpty([Artist]),, , [Artist])
-
Ok, then you need to make similar checking for every field (or maybe use that IfElse structure). I need to go now so I can't make the expression for you right now but I can help later if someone else hasn't by the time I available again.
OK, thanks. ;)
I tried to extend the "If(IsEmpty" to the other fields, but I suspect I need something different; as depending of which fields are empy I still get an unwanted comma somewhere.
-
Try this:
listbuild(1, /,/ , [Composer] - [Album] By [Conductor], [Artist], [Orchestra])IfElse(!IsEmpty([Date]), / - [Date])
It doesn't handle and empty Conductor. If you need to handle empty Composer, Album, and Conductor, this can be accomplished using a sequence of If(!isempty()) statements.
-
Try this:
listbuild(1, /,, [Composer] - [Album] By [Conductor], [Artist], [Orchestra])IfElse(!IsEmpty([Date]), / - [Date])
This works only if I have a Conductor; if the conductor field is empy I get a comma before the artist:
Beethoven - Piano Sonata No.29 Op.106 by ,Pollini
Puff, I couldn't imagine it was so complicated... ;)
-
Can you live with <unknown> for an empty value?
The reason it is complicated is that before outputting any given value's separator, you have to consider the value and the next value down the line.
-
Can you live with <unknown> for an empty value?
Well, maybe it's better I do not use commas and put only a <space> between fields; take in mind only a minority of records have all the 3 fields filled: I'd say Concertos and Operas; in a Symphony you miss the Artist, in a Piano Sonata you miss Conductor and Orchestra, etc.
-
Let's use listbuild 3 times to add the different separators. This should do it.
listbuild(1, /,/ ,
listbuild(1, / -/ , [Composer],
listbuild(1, / By/ , [Album], [Conductor])), [Artist], [Orchestra])IfElse(!IsEmpty([Date]), / - [Date])
Copy/Paste using the Expression Editor (via the pulldown triangle when you enter the value for the expression).
-
Finally, with listbuild, we can now get rid of the if() test:
listbuild(1, / -/ , [Composer],
listbuild(1, / By/ , [Album], listbuild(1, /,/ , [Conductor], [Artist], [Orchestra])), [Date])
-
Finally, with listbuild, we can now get rid of the if() test:
listbuild(1, / -/ , [Composer],
listbuild(1, / By/ , [Album], listbuild(1, /,/ , [Conductor], [Artist], [Orchestra])), [Date])
Yes, this one worked.
Thank you very much, I really appreciated.
-
You're welcome. Once I stood back to re-examine the problem, the solution became clear.
Glad it works for you.
Cheers.
-
I recicle my old thread for another expression help. ;)
I wrote an expression for the title of not-classical music view, to have the albums sorted by date (if present) and not alphabetically:
[Artist] If(IsEmpty([Date]),, ([Date])) - [Album]
this way I get, for instance:
King Crimson (1973) - Larks' Tongues in Aspic
BUT, if the date field is empty I get this:
King Crimson ) - Larks' Tongues in Aspic
I don't understand why I get this closed parenthesis...
Thanks
P.S. Maybe I'm making complicated a simple thing, i.e.: there's a better way to get the same result?
-
You need to escape the parenthesis that are not part of the expression:
[Artist] If(IsEmpty([Date]),, /([Date]/)) - [Album]
Try that, it should work now. :)
-
Yes!
Thank you. ;)