Hello makers, any idea to simplify this :
In few words, depending on defined terms, I want to tag as “Agence”, and in any other case, it’s “B2C”.
I’m sure I can optimize but don’t know how.
Hello makers, any idea to simplify this :
In few words, depending on defined terms, I want to tag as “Agence”, and in any other case, it’s “B2C”.
I’m sure I can optimize but don’t know how.
Could you provide examples where you want “Agence”, and other examples where you want “B2C”?
samliew – request private consultation
Join the Make Fans Discord server to chat with other makers!
It’s stored in a Google Sheet.
It works like a converter :
If those exact terms Agence
If not B2C
How are you getting the values from the Google Sheet?
Please provide sample output bundles.
Please provide the output bundles of the Google Sheet modules by running the scenario (or get from the scenario History tab), then click the white speech bubble on the top-right of each module and select “Download input/output bundles”.
Save each bundle contents in your text editor as a bundle.txt
file, and upload it here into this discussion thread.
Uploading them here will look like this:
module-1-output-bundle.txt (12.3 KB)
If you are unable to upload files on this forum, alternatively you can paste the formatted bundles in this manner:
Either add three backticks ```
before and after the code, like this:
```
input/output bundle content goes here
```
Or use the format code button in the editor:
Providing the input/output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.
This will allow others to better assist you. Thanks!
samliew – request private consultation
Join the Make Fans Discord server to chat with other makers!
No, data comes from Webhook and I’m storing it in Google Sheet by converting it as “Agence” or “B2C”.
It’s been working for months, I just want to know if there is a better way to do so?
You can use a regular expression if you don’t want a switch function.
But I need to know what you are trying to match to be able to assist with that.
I can’t commercially show you but imagine that is Fruit’s name :
If equal Strawberry, Ananas, Banana, Cherry (…and this list will get longer and longer) Agence
If not B2C
If you mean better in terms of scalability, sure. You can set up a data store where “Strawberry” and “Banana” are keys. Then, use a simple module like “Data Store: Check the existence of the record,” and you’re good to go.
You can also search for “Cherry”/ “Apple” and so on in Google Sheets.
However, if we’re thinking in terms of operation usage and costs, the Switch module is the cheapest—do not consume extra operations like examples above.
Keep your list of Agence somewhere like a Data Store or Google Sheet.
In the scenario, read that list into an array.
Use array functions (I think “contains()” ) to check if the array contains your Payeur, and if so then tag it as Agence, otherwise as B2C.
Thank you @Donald_Mitchell @mszymkowiak
Actually, we unconsciously listed them in the same Google Sheets but in a different sheet as I store the following data :
I think something like that should work so
But how to “read that list into an array” ? Should I use a new module? Or may I directly make it into the function?
If using Google Sheets, use Get Range Values and pull the list from the sheet using A:A as the Range (use whatever letter of the column the items are in).
That will return 1 bundle for each row.
Use array aggregator to aggregate the list into an array of collections, each collection containing just the value from the cell.
Using the map() function on that array, you can pull the value from each collection of the array into a new array of text strings.
This final array contains the existing list of items.
Now, when you use if(contains(existing list;Strawberry);Agence;B2C) it will return Agence if Strawberry is in the list or B2C otherwise.
Definitely, the words “array”, “collections”, “aggregator”, “iterator” will make me scared as far as I get an individual course one day
I made the following scenario to test, let’s test :
Thank you Donald
Here’s an example. Just copy this text and paste into a scenario - Make will know how to create modules from it. The Parse JSON represents Google Sheets output, I did it this way so it’s all self-contained and will run immediately without any modification.
{
"subflows": [
{
"flow": [
{
"id": 7,
"module": "json:ParseJSON",
"version": 1,
"parameters": {
"type": ""
},
"mapper": {
"json": "[\n {\n \"0\": \"Fruits\",\n \"__ROW_NUMBER__\": 1,\n \"__SPREADSHEET_ID__\": \"/1pwVRcrI1yR8ZyngQXQpQBCg1XtANz7Sh/19zDecnNUxmw735pwk9P3u5PUHF8Knnig0uP0RoFvFKI\",\n \"__SHEET__\": \"Sheet8\",\n \"__IMTLENGTH__\": 6,\n \"__IMTINDEX__\": 1\n },\n {\n \"0\": \"Apple\",\n \"__ROW_NUMBER__\": 2,\n \"__SPREADSHEET_ID__\": \"/1pwVRcrI1yR8ZyngQXQpQBCg1XtANz7Sh/19zDecnNUxmw735pwk9P3u5PUHF8Knnig0uP0RoFvFKI\",\n \"__SHEET__\": \"Sheet8\",\n \"__IMTLENGTH__\": 6,\n \"__IMTINDEX__\": 2\n },\n {\n \"0\": \"Banana\",\n \"__ROW_NUMBER__\": 3,\n \"__SPREADSHEET_ID__\": \"/1pwVRcrI1yR8ZyngQXQpQBCg1XtANz7Sh/19zDecnNUxmw735pwk9P3u5PUHF8Knnig0uP0RoFvFKI\",\n \"__SHEET__\": \"Sheet8\",\n \"__IMTLENGTH__\": 6,\n \"__IMTINDEX__\": 3\n },\n {\n \"0\": \"Orange\",\n \"__ROW_NUMBER__\": 4,\n \"__SPREADSHEET_ID__\": \"/1pwVRcrI1yR8ZyngQXQpQBCg1XtANz7Sh/19zDecnNUxmw735pwk9P3u5PUHF8Knnig0uP0RoFvFKI\",\n \"__SHEET__\": \"Sheet8\",\n \"__IMTLENGTH__\": 6,\n \"__IMTINDEX__\": 4\n },\n {\n \"0\": \"Mango\",\n \"__ROW_NUMBER__\": 5,\n \"__SPREADSHEET_ID__\": \"/1pwVRcrI1yR8ZyngQXQpQBCg1XtANz7Sh/19zDecnNUxmw735pwk9P3u5PUHF8Knnig0uP0RoFvFKI\",\n \"__SHEET__\": \"Sheet8\",\n \"__IMTLENGTH__\": 6,\n \"__IMTINDEX__\": 5\n },\n {\n \"0\": \"Strawberry\",\n \"__ROW_NUMBER__\": 6,\n \"__SPREADSHEET_ID__\": \"/1pwVRcrI1yR8ZyngQXQpQBCg1XtANz7Sh/19zDecnNUxmw735pwk9P3u5PUHF8Knnig0uP0RoFvFKI\",\n \"__SHEET__\": \"Sheet8\",\n \"__IMTLENGTH__\": 6,\n \"__IMTINDEX__\": 6\n }\n]"
},
"metadata": {
"designer": {
"x": 0,
"y": 0
},
"restore": {
"parameters": {
"type": {
"label": "Choose a data structure"
}
}
},
"parameters": [
{
"name": "type",
"type": "udt",
"label": "Data structure"
}
],
"expect": [
{
"name": "json",
"type": "text",
"label": "JSON string",
"required": true
}
]
}
},
{
"id": 8,
"module": "builtin:BasicAggregator",
"version": 1,
"parameters": {
"feeder": 7
},
"mapper": {
"0": "{{7.`0`}}"
},
"metadata": {
"designer": {
"x": 300,
"y": 0
},
"restore": {
"extra": {
"feeder": {
"label": "JSON - Parse JSON [7]"
},
"target": {
"label": "Custom"
}
}
}
}
},
{
"id": 11,
"module": "util:SetVariables",
"version": 1,
"parameters": {},
"mapper": {
"variables": [
{
"name": "Existing Items",
"value": "{{map(8.array; 0)}}"
}
],
"scope": "roundtrip"
},
"metadata": {
"designer": {
"x": 600,
"y": 0
},
"restore": {
"expect": {
"variables": {
"items": [
null
]
},
"scope": {
"label": "One cycle"
}
}
},
"expect": [
{
"name": "variables",
"type": "array",
"label": "Variables",
"spec": [
{
"name": "name",
"label": "Variable name",
"type": "text",
"required": true
},
{
"name": "value",
"label": "Variable value",
"type": "any"
}
]
},
{
"name": "scope",
"type": "select",
"label": "Variable lifetime",
"required": true,
"validate": {
"enum": [
"roundtrip",
"execution"
]
}
}
],
"interface": [
{
"name": "Existing Items",
"label": "Existing Items",
"type": "any"
}
]
}
},
{
"id": 12,
"module": "util:SetVariables",
"version": 1,
"parameters": {},
"mapper": {
"variables": [
{
"name": "Apple Exists?",
"value": "{{contains(11.`Existing Items`; \"Apple\")}}"
},
{
"name": "Blueberries Exists?",
"value": "{{contains(11.`Existing Items`; \"Blueberries\")}}"
},
{
"name": "Apple Agence?",
"value": "{{if(contains(11.`Existing Items`; \"Apple\"); \"Agence\"; \"B2C\")}}"
},
{
"name": "Blueberries Agence?",
"value": "{{if(contains(11.`Existing Items`; \"Blueberries\"); \"Agence\"; \"B2C\")}}"
}
],
"scope": "roundtrip"
},
"metadata": {
"designer": {
"x": 900,
"y": 0
},
"restore": {
"expect": {
"variables": {
"items": [
null,
null,
null,
null
]
},
"scope": {
"label": "One cycle"
}
}
},
"expect": [
{
"name": "variables",
"type": "array",
"label": "Variables",
"spec": [
{
"name": "name",
"label": "Variable name",
"type": "text",
"required": true
},
{
"name": "value",
"label": "Variable value",
"type": "any"
}
]
},
{
"name": "scope",
"type": "select",
"label": "Variable lifetime",
"required": true,
"validate": {
"enum": [
"roundtrip",
"execution"
]
}
}
],
"interface": [
{
"name": "Apple Exists?",
"label": "Apple Exists?",
"type": "any"
},
{
"name": "Blueberries Exists?",
"label": "Blueberries Exists?",
"type": "any"
},
{
"name": "Apple Agence?",
"label": "Apple Agence?",
"type": "any"
},
{
"name": "Blueberries Agence?",
"label": "Blueberries Agence?",
"type": "any"
}
]
}
}
]
}
],
"metadata": {
"version": 1
}
}
Thank you @Donald_Mitchell I set this up, I’ll let you know on Monday.
Just for me to learn, how does contain() function work? And mostly, what is the output in case of match?
Given this list in Google Sheets…
In this example…
If the array of items from the spreadsheet (the list of Agence) contains Apple, then the result of the field will be Agence, otherwise B2C. In this case the result is Agence.
For this
It will result in B2C because Blueberries does not exist in the list/array from the spreadsheet.
contains() accept two parameters, the array to check, and the value to check if it’s in the array. Then it returns TRUE or FALSE.
With the if() function, there are 3 parameters, the first is something that should result in TRUE or FALSE (which is the contains() function).
If the the first parameter evaluates to TRUE then the next parameter (Agence) becomes the result of the field.
If the first parameter evaluates to FALSE then the last parameter (B2C) becomes the result of the field.
Hope that helps!