Change the value of Metadata if the condition didn't match in the pre-requist?

This is the data that is passed in the postman.

[
{
        "Metadata": {
            "path": "/api/rest/2.0/user/update",
            "operationId": "update",
            "scenario": "positive"
        },
        "Body": {
            "username": "abcd",
            "object_id": "061450",
            "password": "abc@123"
        }
    }
]

I would to change the value of the scenario if the condition in the pre-request did not match.

My approach to do is:
if the condition didn’t match, then I’m calling this statement
pm.iterationData.toObject()[‘Metadata’][‘scenario’] = “negative”

How and where in Postman is that object currently set?

How is it being sent with with request? For example, how exactly are you setting the body for the request.

You appear to be using pm.iterationData which would indicate you are using a CSV or JSON import file. Is that correct?

Pretty sure the iterationData is read only, so you can’t update the elements directly, so you would have to initialize a variable and then update the scenario element within that variable, and then use that variable for the body.

Lastly, your response is an array with a single object in it. So you need to target that using the array index of [0].

body = pm.iterationData.toObject();
console.log(body);
body[0].Metadata.scenario = "negative";
console.log(body);
pm.request.body.raw = body;