My question:
Hi all, I’m trying to match a pattern in json response array, perhaps it is not a straight forward text match.
Let me describe the challenge I have.
I have the following json as response:
[
{
“description”: " (1997-2000) 1234vol",
“ID”: “486”,
“addendum”: “1”
},
{
“description”: " (2000-2001) 1234vol",
“ID”: “486”,
“addendum”: “2”
},
{
“description”: “4T (2008-2018) 1234vol”,
“ID”: “1324”,
“addendum”: “1”
},
{
“description”: “4T (2018-2021) 1234vol”,
“ID”: “1324”,
“addendum”: “2”
},
{
“description”: “4T UBS (2018-2021) 1234vol”,
“ID”: “8745”,
“addendum”: “1”
},
{
“description”: “Bat (2001-2004) 1234vol”,
“ID”: “387”,
“addendum”: “1”
},
{
“description”: “Cat (2003-2004) 1234vol”,
“ID”: “387”,
“addendum”: “2”
},
{
“description”: “Cat (2004-2007) 1234vol”,
“ID”: “387”,
“addendum”: “3”
},
{
“description”: “Val (2007-2012) 1234vol”,
“ID”: “387”,
“addendum”: “5”
},
{
“description”: “Cat (2012-2018) 1234vol”,
“ID”: “387”,
“addendum”: “5”
},
{
“description”: “Nasty (2013-2017) 1234vol”,
“ID”: “4970”,
“addendum”: “1”
}
]
and I have ID and Year already declared in collection variables.
Now what I’m strugling with is to identify the right description.
E.g.
(“ID”,387) and (“Year”,2008)
So far I managed to match the ID in the array
if (el.ID===(pm.collectionVariables.get(“ID”))) {
pm.collectionVariables.set(“Description”,(el.description))
pm.collectionVariables.set(“Addendum”,(el.addendum));
return;
}
});
perhaps this will always end up with selecting the description “Cat (2012-2018) 1234vol”
I cannot figure out how to match the description “Val (2007-2012) 1234vol” that would be the right one given the input variable is year 2008