Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added compareLists #14

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Bobspadger
Copy link

compare listA vs listB for allowed values

This will check to see if a Value is in the both lists and therefore a match - useful for checking if store ID's etc exist in magento - may be useful for your collection.

Alex

compare listA vs listB for allowed values
@filemakerstandards
Copy link
Owner

Bob, thanks so much for contributing. This is exactly what I had hoped would happen as people become familiar with git/github and start using the filemakerstandards collection of CF's.

With regards to this particular function, I'm left wondering if it's really needed. The semantic naming of the function may contribute to making code more readable, but the functionality of the CF is pretty much Filter ( ~selected ; ~allowed ). The simplicity of the code can easily be accomplished with IsEmpty ( Filter ( ~selected ; ~allowed ) ) for a boolean result.

I'll let others on the list weight in on this viewpoint.

One other thing I would mention is putting 'list' based functions within a List* collection. Such as ListCompare, ListExclude, ListCombine, etc. We do this with Value and other groupings of functions.

@filemakerstandards
Copy link
Owner

Also, did you mean to use Filter or FilterValues() ?

@Bobspadger
Copy link
Author

Hi

My thinking on this came from integrating magento with our database and enabling multiple stores.

As I have relationships to say that a product can be in website 1 and 2, but only in store 5 , 7 and 9 I needed a way to check I did not have any incorrect numbers in either the stores or the website field.

We have value lists, based on the relationships, and then checkboxes to select the website and store
So, selecting website 1 will give you the option of stores 1,2,3 etc as checkboxes.

The trouble with filemaker is that if you select the stores in different orders, the field can contain 3 1 2 / 1 2 3 / 2 1 3 etc.
The second part of the problem was if you removed a product from website 1 , these store ID's were no longer valid, so I needed to check that they were correct, so it reports back on this too.
eg
Website 1 has stores 1 2 3
Website 2 has stores 4 5 6

Product is in Website 1 and 2 so has the possibility of being in stores 1 2 3 4 5 6 (thats not to say it will be in all stores)

Product is then removed from websites 1, so stores 1 2 3 are now invalid. (and so the value list for selecting the stores changes - however, it leaves the data in the field but the checkboxes look ok to the end user)
If the mechanism for removing the id's from the stores fails, we can have incorrect id's for API calls updates etc.

Essentially, this allows us to check if the values are correct, regardless of their order and it works in both directions
I've used it in scripts and conditional formatting to highlight to users at different points that there may be an error.

I hope that makes sense!

Cheers

Alex

@dansmith65
Copy link
Collaborator

Bob, can you compare the custom function you are actually using in your database with the file in your commit? Like Matt said, I think you meant to use the FilterValues function instead of just Filter.

I think the standard for a function like this is to return a boolean value rather than a text value.

I also think the function name is ambiguous. Something along the lines of ListsContainSameValues is clearer. When it's just called "compareLists", how are you supposed to know what type of comparison is being performed?

@Bobspadger
Copy link
Author

Hi Dan

I'll take a look , and yes I agree the name is possibly ambiguous. Maybe something like listContainsValidValues ?

I can change it to boolean no problem, its probably a good thing to do and I'll update this in my solution as well.

I'm not sure on the filter vs filterValues - I'll need to give it a check over as I wrote is a few months ago and would need to check my workings on different input variables!

@Bobspadger
Copy link
Author

ok, function in my live copy was a boolean output - I've updated to this and added some more notes.

If I user filterValues, I do not get the correct result for the output as I'm looking for checking that the values are an allowed combination

Example being.

Product is enabled in website 1
This has stores 1 and 2

~allowed list = 1
~selected list = 1

Output = 0 - all match

~allowed list = 1
~selected list = 1 2

Output = 1 - error, the selected list has an invalid value in

Example 2:

~allowed list = 1 3
~selected list = 3
output = 0

~alloed list = 1 3
~selected = 1 2 3 or any order etc
output = 1 - error

Could possibly change the logic round ? for 1 = ok, 0 = error ?
Also, the name does need changing, suggestions welcome.

@dansmith65
Copy link
Collaborator

I think, as the function is named and described, it should be using FilterValues instead of just Filter. In your use-case, the values only contain a single character so it hasn't mattered which function was use.

I think what you meant to write was this: https://gist.github.com/dansmith65/8249869
That function returns True if all ValuesToTestExistence exist in ValueList.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants