Sudi
Sudi

Reputation: 13

How to set environment variable using a data file in Postman

I have a data file having a column userid, now i want to set a environment variable based on the value of userid using pre-request script.

var i = data.userId;
console.log(i);

if(i==='1')
{
    pm.environment.set("id","i");
    //console.log(pm.environment.get("id"));
}

Can someone please help

Upvotes: 1

Views: 1941

Answers (1)

Danny Dainton
Danny Dainton

Reputation: 25921

I would have thought that you would need to adjust the script to something like this:

var i = pm.iterationData.get("userId");
console.log(i);

if( i === '1' )
{
    pm.environment.set("id", i);
   //console.log(pm.environment.get("id"));
}

Upvotes: 1

Related Questions