INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Library field that copies another field if it is empty  (Read 870 times)

Mike Foran

  • World Citizen
  • ***
  • Posts: 212
Library field that copies another field if it is empty
« on: May 22, 2019, 08:28:25 pm »

I've created a custom library field called 'Year (Release)' to distinguish the year an album was actually released, vs. when the music was actually created. I'd like to set it up with an expression that, if the field has no data, would copy the data from the 'Year' field. But if there is data in the field, it would display that instead. Is it possible to do something like this?

EDIT: to clarify, can a field have either an expression OR manually entered data?
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: Library field that copies another field if it is empty
« Reply #1 on: May 22, 2019, 09:20:04 pm »

MC already has a [Date (released)] field. Why not use that? Although it wouldn't allow the functionality you are looking for as it is a standard field, you could set up a tag on import expression to save the value in the [Year] tag to the [Date (released)] field, if the [Date (released)] tag is empty.

But if you really want to use your new [Year (Release)] field, I think you can make it a "calculated data" field and include an expression that tests the [Year (Release)] field itself to see if it is empty, and if so set it to the [Year] field, if not set it to its current value.

I'm just not sure when and how often that gets calculated though. At record creation definitely.

Try it and see.
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

Mike Foran

  • World Citizen
  • ***
  • Posts: 212
Re: Library field that copies another field if it is empty
« Reply #2 on: May 22, 2019, 09:50:11 pm »

MC already has a [Date (released)] field. Why not use that?

LOL I missed that field so yeah I will move to that.

But if you really want to use your new [Year (Release)] field, I think you can make it a "calculated data" field and include an expression that tests the [Year (Release)] field itself to see if it is empty, and if so set it to the [Year] field, if not set it to its current value.

Yes, exactly, it's the expression itself that I'm having trouble with. I'm not great with the syntax. I can get it to mirror 'Year' if it is empty, but I can't get it to override with manual data. Not sure how to do it.
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: Library field that copies another field if it is empty
« Reply #3 on: May 23, 2019, 02:17:06 am »

Well I haven't tested if a custom calculated field can be overwritten by direct data entry, but the expression I was thinking of would be along the lines of;

if([Year (Release)]=[], [Year (Release)]=[Year], [Year (Release)])
Reference: https://wiki.jriver.com/index.php/Conditional_Functions#If

But if you switch to using the [Date (released)] field then that is no longer required. A similar expression could be used for tag on import though.

A lot of metadata sources do have a release date for Albums and Singles, though not all of course. You may find that the [Date (released)] field is already populated if you added it to Views, or could be with lookups using tools such as MusicBrainz.
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Library field that copies another field if it is empty
« Reply #4 on: May 23, 2019, 05:57:14 am »

What you are looking for is a field that behaves like [Album Artist (auto)] .  [Album Artist (auto)] normaly takes the value of [Album Artist].
 But if it's empty, it takes the value of [Artist].  The code looks like this:

FirstNotEmpty([Album Artist], [Artist])

So [Album Artist] is your override field and it falls back to [Artist] otherwise.

What you probably want is something like [Date Release (auto)] with a calculated value like:

FirstNotEmpty([Date (released)], [Date])

I hope that helps.

Brian.
Logged

Mike Foran

  • World Citizen
  • ***
  • Posts: 212
Re: Library field that copies another field if it is empty
« Reply #5 on: May 23, 2019, 08:04:58 am »

What you are looking for is a field that behaves like [Album Artist (auto)] .

Thanks Brian. Yes, that's pretty much it. But this requires a third field to do the Auto calculation, correct? So I would need [Artist] [Album Artist] and then [Album Artist (Auto)] to make it work. But [Album Artist (Auto)] would not be able to accept manual input. I'm looking to see if it can be done with two fields. The first would be a standard input, the second would evaluate itself to see if it were empty, and if so copy the data in the first, but if not, to display the manual data.

I don't think it can be done. I get a circular reference. I'm guessing that a field can't both have an expression AND manual data.
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8014
Re: Library field that copies another field if it is empty
« Reply #6 on: May 23, 2019, 09:05:42 am »

You can not do this with only two fields.  You need 3, as you have observed.  In your case, [Date], [Date Released], [Date (auto)] .

You can think of it this way:  [Date] is the default date that will end up in [Date (auto].  But if you want to override this, you put your manual value in [Date Released].  Then [Date (auto)] will have the value of [Date Released].

[Date (auto)] is a calculated field.

This should work just fine for you.  I'm assuming you are using this for sorting.  Just sort using [Date (auto)] and you're all set.

Brian.
Logged

Moe

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 718
  • Hi
Re: Library field that copies another field if it is empty
« Reply #7 on: May 23, 2019, 12:31:03 pm »

This is very cool and I had an issue last night that this is perfect for, thanks Brian.
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: Library field that copies another field if it is empty
« Reply #8 on: May 23, 2019, 10:18:09 pm »

Note that MC does actually allow you to manually enter a value into the [Album Artist (Auto)] field, even though it is a calculated field. But it can give strange results, and may only work because it uses a coded function, not an expression, and seems to in fact write any entered value into [Album Artist]. Well, depending on what other fields have data.

That may have some implications for the above discussion though. I haven't tested.

But a new field called perhaps [Release Date] which uses the expression FirstNotEmpty([Date (released)], [Year]) would do what you originally asked about.

Getting the correct metadata into the standard [Date (released)] field would also do it.
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner
Pages: [1]   Go Up