Sorting a List of JSON Maps by a Specific Field using Zoho Deluge
- Hugh Marshall
- Jul 1, 2023
- 2 min read
Updated: Aug 22, 2023
When you use custom functions in Zoho CRM, you will often find yourself dealing with lists of JSON maps. One thing that you cannot do natively with deluge is sort a list of JSON maps by a specific field, but you can sort a list of values. We can use this to our advantage.
Let's take this list of tasks that we have here in JSON format, as well as the data represented as a table.
We can see that the data is currently sorted by the 'id', but we want to sort it using the 'due date' with the oldest at the top. For us, that is a much more realistic way to view our upcoming and overdue tasks.
Example Code
Using this snippet of code, we can achieve what we are after. I'll explain in detail all the components that make it work.
How it works
First, we iterate through all of the tasks in the list and retrieve the value we want to sort by, which in this case is the 'Due_Date.' We save each of these values to another list called 'unsortedKeys'. In situations where the value is not unique and there's a possibility of having the same value for multiple records, I like to append the record's ID to the end of the value. This is done as a precautionary measure, as the sorting process will not work if there are any duplicate keys.
Simultaneously, while iterating through the tasks, we also create a new Map called 'unsortedKeyValueData'. In this Map, we use the sorting value as the key and the task data as the corresponding value. This mapping allows us to easily locate a task based on its unique key value.
Sorting the Keys
Since the 'unsortedKeys' list only contains values, we can now sort these values using the deluge sort function. By doing so, we can arrange the keys in ascending order. In the case of dates, this means the oldest date will appear first.
Reordering the List
Now that we have a sorted list of keys, all we need to do is iterate through this list. During each iteration, we retrieve the corresponding values from the 'unsortedKeyValueData' map we created earlier. We can then add these values to a new list which will be in the order we want.
Here is an example of the result we achieved.
By following the steps outlined above, you can effectively sort any list of JSON Maps by a specific field. This is really useful especially when you are building custom related lists or reordering subform records. Happy sorting!
Need Help? Contact us!
I recommend that you read some of this information so that it can be used as a reference in writing articles: Info 1 Info 2 Info 3 Info 4 Info 5 Info 6 Info 7 Info 8 Info 9 Info 10 Info 11 Info 12 Info 13 Info 14 Info 15 Info 16 Info 17 Info 18 Info 19 Info 20 Info 21 Info 22 Info 23 Info 24 Info 25 And this Link 1 Link 2 Link 3 Link 4 Link 5 Link 6 Link 7 Link 8 Link 9 Link 10 Link 11 Link 12 Link 13 Link 14 Link 15 Link 16 Link 17 Link 18 Link 19 Link 20 Link 21 Link 22 Link 23 Link 24 Link 25 Then this Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Page 9 Page 10 Page 11 Page 12 Page 13 Page 14 Page 15 Page 16 Page 17 Page 18 Page 19 Page 20 Page 21 Page 22 Page 23 Page 24 Page 25 Next this Post 1 Post 2 Post 3 Post 4 Post 5 Post 6 Post 7 Post 8 Post 9 Post 10 Post 11 Post 12 Post 13 Post 14 Post 15 Post 16 Post 17 Post…
I recommend that you read some of this information so that it can be used as a reference in writing articles: Info 1 Info 2 Info 3 Info 4 Info 5 Info 6 Info 7 Info 8 Info 9 Info 10 Info 11 Info 12 Info 13 Info 14 Info 15 Info 16 Info 17 Info 18 Info 19 Info 20 Info 21 Info 22 Info 23 Info 24 Info 25 Link 1 Link 2 Link 3 Link 4 Link 5 Link 6 Link 7 Link 8 Link 9 Link 10 Link 11 Link 12 Link 13 Link 14 Link 15 Link 16 Link 17 Link 18 Link 19 Link 20 Link 21 Link 22 Link 23 Link 24 Link 25 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Page 9 Page 10 Page 11 Page 12 Page 13 Page 14 Page 15 Page 16 Page 17 Page 18 Page 19 Page 20 Page 21 Page 22 Page 23 Page 24 Page 25 Post 1 Post 2 Post 3 Post 4 Post 5 Post 6 Post 7 Post 8 Post 9 Post 10 Post 11 Post 12 Post 13 Post 14 Post 15 Post 16 Post 17 Post 18 Post 19 Post 20 Post 21 Post 22 Post 23 Post…
I recommend that you read this informations so that it can be used as a reference in writing content: Info 1 Info 2 Info 3 Info 4 Info 5 Info 6 Info 7 Info 8 Info 9 Info 10 Info 11 Info 12 Info 13 Info 14 Info 15 Info 16 Info 17 Info 18 Info 19 Info 20 Info 21 Info 22 Info 23 Info 24 Info 25 Link 1 Link 2 Link 3 Link 4 Link 5 Link 6 Link 7 Link 8 Link 9 Link 10 Link 11 Link 12 Link 13 Link 14 Link 15 Link 16 Link 17 Link 18 Link 19 Link 20 Link 21 Link 22 Link 23 Link 24 Link 25 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Page 9 Page 10 Page 11 Page 12 Page 13 Page 14 Page 15 Page 16 Page 17 Page 18 Page 19 Page 20 Page 21 Page 22 Page 23 Page 24 Page 25 Topic 1 Topic 2 Topic 3 Topic 4 Topic 5 Topic 6 Topic 7 Topic 8 Topic 9 Topic 10 Topic 11 Topic 12 Topic 13 Topic 14 Topic 15 Topic 16 Topic 17 Topic 18 Topic 19 Topic 20 Topic 21 Topic 22 Topic 23 Topic 24 Topic 25 Post…
I recommend that you read some of this information so that it can be used as a reference in writing articles: Info 1 Info 2 Info 3 Info 4 Info 5 Info 6 Info 7 Info 8 Info 9 Info 10 Info 11 Info 12 Info 13 Info 14 Info 15 Info 16 Info 17 Info 18 Info 19 Info 20 Info 21 Info 22 Info 23 Info 24 Info 25 Link 1 Link 2 Link 3 Link 4 Link 5 Link 6 Link 7 Link 8 Link 9 Link 10 Link 11 Link 12 Link 13 Link 14 Link 15 Link 16 Link 17 Link 18 Link 19 Link 20 Link 21 Link 22 Link 23 Link 24 Link 25 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Page 9 Page 10 Page 11 Page 12 Page 13 Page 14 Page 15 Page 16 Page 17 Page 18 Page 19 Page 20 Page 21 Page 22 Page 23 Page 24 Page 25.
FOLLOW THIS:mp3juice mp3juice mp3juice mp3juice mp3juice mp3juice mp3juice mp3juice mp3juice mp3 juice mp3 juice mp3 juice mp3 juice mp3 juice mp3 juice mp3 juice mp3 juice mp3juices mp3juices mp3juices mp3juices mp3juices mp3juices mp3juices mp3juices