Customer Portal

String with container type Map

Comments 1

  • Avatar
    darvehng
    0
    Comment actions Permalink
    Hi Mohamedosharif,

    Thank you for your inquiry. So unfortunately, Clover doesn't have a single function that would be capable of producing this output. However, the good news is this can be done using a combination of functions and data types available via CloverDX's scripting language. I've attached a simple example demonstrating this. Please refer to the code below and after looking at it, feel free to download the example I attached to see the types of components I used and my metadata configuration. I hope this helps. I look forward to hearing from you.


    1. I created two maps - one containing key-value pairs and the other an empty map, which (as you will see) I use later in the for-each loop.
    2. Below the generate function, I created a list and set it equal to the "getKeys" CTL (Clover Transfomation Language) function, which returns the keys (from dummyMap) as a list.
    3. In the next line, I use a for-each loop to loop through all the keys in the "keysList" list created in the previous line.
    4. Because I only want to output key-value pairs with values equal to the string "pass", in each iteration of the for-each loop, I use an "if" condition to check for that specific value and then take that value (along with it's corresponding key) and send it to the other map (dummyOutputMap) as you can see in the last line of the for-each loop.
    _______________________________________________________________________________________________________________
    map[string, string] dummyMap;
    dummyMap["John"]="pass";
    dummyMap["Joe"]="pass";
    dummyMap["Adam"]="fail";
    dummyMap["Jane"]="fail";
    dummyMap["Amber"]="pass";
    dummyMap["Tom"]="pass";

    map[string, string] dummyOutputMap;
    function integer generate() {
    string[] keysList=getKeys(dummyMap);
    foreach(string key: keysList){
    if (dummyMap[key] == "pass"){
    dummyOutputMap[key]=dummyMap[key];
    }
    }
    $out.0.field1 = dummyOutputMap;

    return ALL;
    }

    Best,

Please sign in to leave a comment.