Hello Zoho Creator fans,
I thought I would make a post about some info, tips, ideas, I have around the the Zoho Creator "map" feature....
The map feature can be extremely poweful if you know how to use it. Unfortunately, there isn't a ton of documentation in the Wiki about it's cababilities..
First talk about what a Zoho Creator map is....
A map holds data! You put data in it by first creating a key and then adding a value.
This is called a key, value pair. This key,value concept is used in well known data documents like XML & JSON. And guess what!? Outputted ZC Maps ARE VALID JSON! (Later tutorial)
Maps are great for the following things.......
1. Structuring your data
2. Passing MANY VARIABLES from a form to a funtion or vice versa. (Instead of say one string/Int,List value which can save you much loading and development time)
3. Ceating input agnostic data sets.. (later)
4. Posting JSON to API's using the postURL()/getURL() functions (later)
5. Creating multidimensional traversable arrays just like in other scripting languages (GREAT! later)
//first name a variable.....
myMap = map();
So you just created a map myMap is the variable that holds your map data and map();
Now, we just need to add data to it!
So "key1" is your key and "value1" is your string value associated with the "key1" key...
Let's add some more keys!
Ok, so now we have added two more keys to our "myMap" map and we added some values.. The "key2" key holds an integer, and "key3" holds a bool value..
Notice that you I CAN NAME MY KEYS WHATEVER I WANT! This is VERY IMPORTANT! If you have been playing with Zoho Creator Deluge Script for a while you will start to realize that you cannot dynamically change the "name" of a variable, but since our keys arent' actually a true variable we can dynamically name them.. We will talk about this more later but trust me this is a fantastic little detail that can be uber powerful if you know how to use it.
//Let's get "key1" from myMap
myKeyValue = myMap.get("key1");
There... now myKeyValue will == "value1"
FIRST IN MOST CASES IT'S A BAD IDEA TO CALL A MAP FUNCTION LIKE THIS....
myKey1Value = thisapp.mapFunction().get("key1");
myKey2Value = thisapp.mapFunction().get("key2");
Why? Because unless you added a paramter to the map function to only run a certain part of the map, the FUNCTION IS RUNNING THE WHOLE SCRIPT just to get your one map value... So each time you make a call to this mapfunction you are running the entire script. This won't slow you down with a small function but if you are making calls to web services or collecting records this is just NOT good form...
Like in all good programming it's better to save operations and create A LOCAL map variable... Here's how....
Store your map function key, value pairs in A NEW local variable....
myNewLocalMap = map.put(thisapp.mapFunction());
Now all your keys and values from your map function are IN YOUR LOCAL SCRIPT. Then you just get your values the same way as we did above....
myKeyValue = myNewLocalMap.get("key1");
Ok, there is more to come...
In my next post I will give the goods. This is just a basic post.