✏️ Explanatory Question
Create() Method: Creates a map from the container that was obtained from a previous call to the Map.pack method.
Pack() Method: Serializes the current instance of the Map class.
Below runnable X++ job that demonstrates how to:
MapcontainerMap::create()
static void Job_MapCreateFromContainerExample(Args _args)
{
Map originalMap, restoredMap;
container packedMap;
str key;
int value;
// Step 1: Create a new Map with String keys and Integer values
originalMap = new Map(Types::String, Types::Integer);
// Step 2: Insert key-value pairs
originalMap.insert("Apple", 10);
originalMap.insert("Banana", 20);
originalMap.insert("Cherry", 30);
// Step 3: Pack the map into a container
packedMap = originalMap.pack();
// Step 4: Restore the map from the packed container
restoredMap = Map::create(packedMap);
// Step 5: Display the restored values
key = "Apple";
value = restoredMap.exists(key) ? restoredMap.lookup(key) : -1;
info(strFmt("Key = %1, Value = %2", key, value));
key = "Banana";
value = restoredMap.exists(key) ? restoredMap.lookup(key) : -1;
info(strFmt("Key = %1, Value = %2", key, value));
key = "Cherry";
value = restoredMap.exists(key) ? restoredMap.lookup(key) : -1;
info(strFmt("Key = %1, Value = %2", key, value));
}
pack() and create()?map.pack() turns the map into a container — like compressing a folder.
Map::create(container) unpacks that container — like unzipping the folder back into a map.