We’ve developed some resources to help you work effectively from home during COVID-19 Click to learn more

Store summary of information, 1 key and multiple values

Playing around a bit with CRMScript to learn more and I am trying to achieve a summary of amount of sales per sales type and month to use with Google Charts. But I got stuck with how to store that information after it has been retreived from the database using SearchEngine. From what I can understand, Map are only a key and one value and StringMatrix might not be entirely suitable for this purpose (please correct me if I am wrong).

What's you suggestion how to do this?

Example of what I am trying to get:

Month: TypeA - TypeB - TypeC
2020-06: 11 - 15 - 12
2020-07: 9 - 4 - 6

RE: Store summary of information, 1 key and multiple values

You could create a struct, and make an array of this struct. But if you are going to do updates on already inserted elements, it is a bit cumbersome and inefficient to search the whole array each time to get hold of the correct struct?

But what about using a Map, where they key is the date, and the value is a string with all your values separated by a dash?
Something like this?

Map m;
m.insert("2020-05", "0-0-0");
m.insert("2020-06", "0-0-0");

// Sometime later

String val = m.get("2020-05");
String[] splitted = val.split("-");
splitted[0] = "3";
splitted[1] = "2";
m.insert("2020-05", splitted[0] + "-" + splitted[1] + "-" + splitted[2]);

If you wrap this inside some functions, you can create much cleaner code when using this.

By: Stian Andre Olsen 24 Jun 2020

RE: Store summary of information, 1 key and multiple values

Thanks Stian! Will have a look at that way.

By: Patrik Larsson 25 Jun 2020