If any item in a collection meets condition, then do something…
What is the problem?
Sorry for asking a basic question, but I am not lucky finding the right tutorial for many days now (yes, I started the Make academy, but it will take time…).
So, there has to be a simpler way of doing this. I have a collection of items in the Cognito Forms module. Next comes Google Sheets module. There I want it to output a “No” if at least one of the items in the respective collection is anything other than a “No” (it can be either Yes or No in this case).
Right now I am manually writing a looooong IF formula, listing each of the 18 items. And I need to do this many times in several scenarions. It works, but it’s a lot of work and I’ll have to setup a bunch of filters in the same way on top of that…
firstly → your logic is a bit wrong here. Don’t use one if with a bunch of ands inside, use a nested if chain. So if choice 1 is yes, then no, otherwise if choice 2 is yes, then no, otherwise if choice 3 is yes, then no and so on and so on.
Now for easier processing you can maybe try turning the entire collection to an array using the toArray() function. Then you can use a single contains() function to check if at least one of the values is a yes.
This is because the toArray function turns the collection into an a array of key:value pairs. To get an array of the values, use the map function before the contains:
Its a developer thing about optimizing cpu usage. Technically one value needs to be Yes for everything to be No. So no need to check all the values, just keep checking them one by one until the first Yes.
And about the toArray, can you post the incoming data here so we can check and see how to best transform it?
I was trying multiple versions of what dreamsuite_mike suggests, with parentheses and without, but none is working for me so far. This doesn’t seem to work
Thank you for the exact formula, Stoyan. Still no luck, unfortunately… I must still be doing something wrong. I am also not entirely sure if I am getting it right with the { vs. ( parentheses. My latest attempt is this:
It would be easier if you could provide a blueprint export and an output export of the Cognito forms bundle (instead of just a screenshot).
This way, we can amend it on our end and provide the exact module or value to copy back into your scenario.
To allow others to better assist you, please provide the following:
2. Scenario Blueprint
Providing your scenario will allow others to quickly recreate and see how you have set up the mappings in each module, and also allows us take screenshots or provide module exports of any solutions we have for you in return. This would benefit you in implementing our suggestions as you can view screenshots of the changes or paste corrected modules back into your scenario.
Need help❓View instructions ◀
A. Export Blueprint
In the scenario editor, click the three dots at the top-right, then select “Export blueprint”.
You can upload files and images to this forum by clicking on the upload button:
Uploading an attachment here will look like this: blueprint.json (12.3 KB)
B. Create Public Share Link
In the scenario editor, click on the Share button:
Read more about the scenario sharing feature in the Help Centre.
3. Properly-formatted Output Bundles from a Scenario Run
Please provide the input/output bundles of each of the relevant modules by running the scenario, or get the bundles from a previous run from the Scenario “History” tab.
Providing the bundles from a scenario run will allow others to replicate what is going on, especially if there are complex data structures (nested arrays and collections) and external services. This helps mapping the correct raw variable names from collections (instead of the label/display name).
Need help❓View instructions ◀
Click on the white speech bubbles on the top-right of each module and select “Download output (or input) bundles”.
A. Upload a Text File
Save each bundle contents in a plain text editor as a moduleNumber-output.txt file. Open the file to check if it has not added additional formatting or encoded the plain text.
You can upload files and images to this forum by clicking on the upload button:
Yes, just remove the if(). The contains() function will return a boolean value of true or false, so change the filter from text equal to to boolean equal to.