Welcome Guest

Pages: 1
Add a check for already exists to the User Defined Fields function prior to create
cpkPostMarch 5, 2015, 06:40
Advanced
Posts: 95
Registered:
March 1, 2015, 02:55
Normal topicAdd a check for already exists to the User Defined Fields function prior to create

If it is a simple thing to do, I'd sure like an optional test for "already exists" be added to the User Defined Fields function so that if creating a UD field the same function can only create it if it doesn't already exist.

This is not a huge deal in that I can easily do the same thing with a pretest using the same function with the if but since the pretest is done with the same function I use to create the field then why not give the option to do both in one function call and save a bit of work?

So, lets say I wanted to add a VGMdb UD Text field to every one of my files that don't already have the field, if in the User Defined Fields function there was an additional radio button for "Only If Field Doesn't Exist" or something like that. I suppose it could be a check box instead of an additional radio button so that the other radio button options are there because even though in this case I am creating an empty field and importing or exporting to/from variables in pointless but forced on me. So maybe a radio button for 'do nothing' and then a checkbox for "Only If Field Doesn't Exist".

It seems like it should be pretty easy and certainly has to be useful to someone other than me. 😐

2MR2PostMarch 5, 2015, 08:26
Avatar photo
Administrator
Posts: 2083
Registered:
August 23, 2012, 19:27
Normal topicRe: Add a check for already exists to the User Defined Fields function prior to create

Okay. Will require some thinking. It has to be disabled with a 'prefix' option and there could be possible other issues.

cpkPostMarch 5, 2015, 08:38
Advanced
Posts: 95
Registered:
March 1, 2015, 02:55
Normal topicRe: Add a check for already exists to the User Defined Fields function prior to create

Maybe it should just be automatic because why would anyone want to create a field of the same name anyway? In the help for the function it says "You can however, specify that an item be created if it does not already exist." But this isn't true because I managed to accidentally create the same name field six times plus the one that was already there and so I had seven UD Text fields of the same name in some of my files and then six in the rest that didn't have the field originally. I was quite surprised it let me do that but that. :0 I don't know, just an idea I thought I'd toss out there.

2MR2PostMarch 5, 2015, 14:16
Avatar photo
Administrator
Posts: 2083
Registered:
August 23, 2012, 19:27
Normal topicRe: Add a check for already exists to the User Defined Fields function prior to create

I've no issue adding the options you requested. I'm more curious as to what set of options you have enabled which are letting you create more than one UDTI with the same name. I've tried everything I can think of and I'm not ending up with more than one item. I'm missing something.

cpkPostMarch 5, 2015, 17:38
Advanced
Posts: 95
Registered:
March 1, 2015, 02:55
Normal topicRe: Add a check for already exists to the User Defined Fields function prior to create

LOL! Well I deleted my error but I kind of remember what I did so give me a couple minutes to recreate it. It was an embarrassing mistake in my action code that did it. I'll recreate this time though with fake fields so they can then be easily removed without hurting data. I would have like to have been able to use to the User Defined Fields function with Remove and All but then I would have lost even the valid field that had data in it. Here again a check box that was something "If Empty" would have been nice. Anyway, give me a couple minutes to remember exactly what the combination of mistakes were.

P.S. Don't laugh to hard at my action - It was really embarrassing just to myself. 😡

cpkPostMarch 5, 2015, 17:47
Advanced
Posts: 95
Registered:
March 1, 2015, 02:55
Normal topicRe: Add a check for already exists to the User Defined Fields function prior to create

Okay here it is. Remember, you promised not to laugh at it, right? 😀

Comment The intention of this action to create several User Defined Text Fields and fill them with a temp placeholder value that can be searched on until the information can be found and correctly input.
Comment WARNING!! THIS IS AN EVIL ACTION THAT DUE TO ERRORS DOES NOT DO WHAT IT WAS INTENDED TO DO.…

Set Variable 1 to "placeholder"
Import name of User Defined Text Item BADFIELD1 (Create) from Variable1
Import name of User Defined Text Item BADFIELD2 (Create) from Variable1
Import name of User Defined Text Item BADFIELD3 (Create) from Variable1
Import name of User Defined Text Item BADFIELD4 (Create) from Variable1
Import name of User Defined Text Item BADFIELD5 (Create) from Variable1
Import name of User Defined Text Item BADFIELD6 (Create) from Variable1
2MR2PostMarch 5, 2015, 18:40
Avatar photo
Administrator
Posts: 2083
Registered:
August 23, 2012, 19:27
Normal topicRe: Add a check for already exists to the User Defined Fields function prior to create

I promised I wouldn't laugh and I won't 🙂 You came up with a sequence I never expected ... which I will now fix. So thanks!

Unfortunately the logic is taken literally. Each of your import statements basically says:
- test if UDTI named 'BADFIELD#' exists
- if it doesn't create it
- import the name from Variable 1 (essentially a rename)
- variable 1 never changes and I'm not checking for pre-existing names when doing the rename, only the create.

You're going to end up with 6 UDTIs named 'placeholder'

I'm assuming that you wanted to import the Value which would have created 6 unique UDTIs all of which had a value of 'placeholder'...... but what do I know, I'm the one with the bug.

After the fix, the action as is, will cause all but the first Import to fail.

I will add a test only variant. Also for the import Value I will add only if empty and only if does not exist options. Somehow I'll get all the options to play nice together and have some sort of meaningful action test state when set.

cpkPostMarch 5, 2015, 19:20
Advanced
Posts: 95
Registered:
March 1, 2015, 02:55
Normal topicRe: Add a check for already exists to the User Defined Fields function prior to create

Awesome! I'm looking forward to the expansion of this function. I seem to be using it a lot. That action test state would be nice if it could be used to test various different scenarios for the the UDTI.

Like, set state True(or false if selected) if the field exists, if the field exists AND is empty, if the field does not exist OR is empty.
A rename might be nice too. I have not started an action to deal with this issue but I see that some of my files have fields that are not named consistently, or don't have consistent case. So, me being a person who gets bothered by some of my files having fields named 'barcode' and some 'Barcode' and some 'BARCODE' and they all mean the same thing but still - it bugs me. So, I am going to at some point later today start looking into how to deal with this easily and off the top of my head I think I'm going to have to use multiple calls to the same function to find the various different variations and if they exist export the value to a variable, delete the bad cases, create a field named consistently (I think in this case I'll choose BARCODE since that is what FLAC is and the encoding my archived music is mostly in). But it would sure be nice if it were possible to 'rename if exists' were a possibility.

I've also some files that have something like 'MusicBrainz Track ID' and 'MUSICBRAINZ_TRACKID' which is also really annoying and I'm going to have set about figuring out an action to fix. And what it the values are different? Then something isn't right so I will want to be able to compare the values in the UDTIs but off the top of my head I think that will also mean multiple calls to the same function and exporting to variables and comparing the variables because I don't recall being able to compare UD Text fields directly.

Anyway, yep, you guessed it - I had meant to import the value. I had just clicked the wrong radio button and then copy/pasted the same function multiple times changing only the field name and ignoring the radio buttons and then ran it and had a bunch of the same field. Careless mistake on my part - I know better but obviously wasn't paying enough attention to what I was clicking. 🙁

Pages: 1
Mingle Forum by Cartpauj | Version: 1.1.0beta | Page loaded in: 0.019 seconds.