I need to save all instances of a tag within the response within globals so I can call them in following tests

I need to save all instances of a tag within the response within globals so I can call them in following tests.

Here is an example response:

{
“Products”: [
{
“UniqueId”: “9e82”,
“Title”: “Economy Weekly”,
“Status”: 1
},
{
“UniqueId”: “9p22”,
“Title”: “Psychology Weekly”,
“Status”: 3
},
{
“UniqueId”: “9p82”,
“Title”: “Earth Science Weekly”,
“Status”: 3
},
{
“UniqueId”: “9p89”,
“Title”: “Fashion Weekly”,
“Status”: 0
},
“ResponseCode”: 0
}

I’d like to save the “UniqueId” for each object then store all of these individually in globals with different names. So, in the next request I can refer to each of these and check details of each product. How do I do this?

Here is a code sample that gets the JSON response, loops through the array, and for for ever “carrier object” gets the UniqueID.

let jsonData = pm.response.json();
var i = 0;
    //for each object in the array
    jsonData.carriers.forEach(function(entry) {
        console.log(i + ' ' + entry.UniqueId);
        //get the varable value
        var uniqueId_val = entry.UniqueId
        pm.globals.set(i, uniqueId_val);
        i++;
    });

I spun up a Mock server that returns:

{
	"carriers": [{
			"UniqueId": "9e82",
			"Title": "Economy Weekly",
			"Status": 1
		},
		{
			"UniqueId": "9p22",
			"Title": "Psychology Weekly",
			"Status": 1
		},
		{
			"UniqueId": "9p82",
			"Title": "Earth Science Weekly",
			"Status": 1
		},
		{
			"UniqueId": "9p89",
			"Title": "Fashion Weekly",
			"Status": 1
		},
		{
			"UniqueId": "9e82",
			"Title": "Weekly Weekly",
			"Status": 1
		}
	]
}

Thank you very much! This is really helpful.

Do you know if theres a way to then refer to each of these saved globals in another request that will just run through and hit all the uniqueids one after the other without needing to create multiple requests?

if you know the variable key, you can use:
pm.globals.get("variable_key");