String with container type Map

Support/help with CloverETL (4.9) and CloverDX (5.0 or newer) implementation problems

mohamedosharif
Posts: 18
Joined: Tue Dec 11, 2018 9:19 pm

String with container type Map

Postby mohamedosharif » Mon Oct 21, 2019 4:27 pm

I have a string defined in the metadata in which the 'Container Type = Map', when it runs, it gives me an output

Code: Select all

{consecutive_month_check=fail, scientific_notation_check=success, extended_cost_check=success, monthly_row_variation_check=fail, monthly_spend_variation_check=fail, unit_of_measure=success, contract_type=success, contract_description=success, department_name=fail, department_code=fail, manufacturer_name=success, manufacturer_catalog_number=success, item_number=success, vendor_catalog_number=success, category_description=success, eaches_per_uom=success, category_code=success, price_per_each=success, extended_cost=success, facility_name=success, contract_number=success, contract_start_date=success, contract_end_date=success, po_number=success, po_line_number=success, po_date=success, item_description=success, vendor_name=success, units=success, facility_id=success, staging_duplicates=success, production_duplicates=null, facility_spend_variation=success, facility_row_variation=success, production_duplicate_status=success}


in the step following this, i would like to only pull the outputs that are 'fail', so it would look like this.

Code: Select all

{consecutive_month_check=fail, monthly_row_variation_check=fail, monthly_spend_variation_check=fail, department_name=fail, department_code=fail, }


is there a clover function that can do this for me?

darvehng
Posts: 7
Joined: Mon Apr 08, 2019 4:40 pm

Re: String with container type Map

Postby darvehng » Thu Oct 31, 2019 5:38 pm

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,
Attachments
solutionForForumTicket.grf
(2.27 KiB) Downloaded 6 times
---
George Darvehn
CloverCARE Support
CloverDX

Visit us online at http://www.cloverdx.com