Zoho Flow Custom Function - Collection Error
I have setup a custom function that takes a string value I receive from a webhook which is the full address provided by a user.
I want to break this address into it's pieces so as to map each piece to Zoho CRM fields (ie. street, city etc).
This function worked fine before I added in logic to loop over the collection to check if specific values are there and map them accordingly (ie. check which element in the collection is the country and then map to country output).
Without the if statement logic things work fine. With the if statement logic I am getting an error about an invalid collection.
Here is the function:
- map FlexiPerk_Location_AddressSplit(string location)
- {
- // Initialize the output values to empty strings
- street = "";
- suburb = "";
- city = "";
- province = "";
- country = "";
- postalCode = "";
-
- // Define the list of provinces and countries
- provinces = ["Eastern Cape", "Free State", "Gauteng", "KwaZulu-Natal", "Limpopo", "Mpumalanga", "North West", "Northern Cape", "Western Cape"];
- countries = ["South Africa"];
-
- // Split the location into its components
- components = location.toListString();
- info components;
-
- // Check the length of the components list
- if (components.length == 1) {
- street = components.get(0);
- } else {
- // Loop through the components and check for the province, country, and postal code components
- for each locationElement in components {
- if (provinces.contains(locationElement)) {
- province = locationElement;
- } else if (countries.contains(locationElement)) {
- country = locationElement;
- } else if (locationElement.length == 4) {
- postalCode = locationElement;
- } else {
- // If the component is not the province, country, or postal code, add it to the street value
- if (street != "") {
- street += ", ";
- }
- street += locationElement;
- }
- }
- }
- info street;
- info suburb;
- info city;
- info province;
- info country;
- info postalCode;
-
- // Create a map to store the output values
- outputMap = Map();
- // Assign the output values to the output map
- outputMap.put("street", street);
- outputMap.put("suburb", suburb);
- outputMap.put("city", city);
- outputMap.put("province", province);
- outputMap.put("country", country);
- outputMap.put("postalCode", postalCode);
-
- output = outputMap;
- return output;
- }
Any idea how to fix?
Access your files securely from anywhere
Zoho Developer Community
Deliver unforgettable customer experiences
Deliver unforgettable customer experiences
New to Zoho Marketing Plus?
Everything you need to run your marketing
New to Zoho Marketing Plus?
Everything you need to run your marketing
Zoho Desk Resources
-
Desk Community Learning Series
-
-
-
-
-
-
-
-
-
Zoho TeamInbox Resources
Zoho DataPrep Resources
Zoho CRM Plus Resources
Zoho Books Resources
Zoho Subscriptions Resources
Zoho Projects Resources
Zoho Sprints Resources
Qntrl Resources
Zoho Creator Resources
Zoho Campaigns Resources
Zoho CRM Resources
Zoho Show Resources
Writer Get Started. Write Away!
Writer is a powerful online word processor, designed for collaborative work.