There is an bug in postman. In post request when we replace 99 to 101 keys with any values are not replaceable by postman prerequisite script

eg json {“Requester”: “Requestor”:{ “Id”:1, “Channel ID”: “101”} }

In prerequisite script:
Var ChannelID = Json.parse(pm.request.body.raw).Requester Requetor.ChannelID;

Var rawdata = Json.parse(pm.request.body.raw).replace(ChannelID,“401”);
Console.log(rawdata)

Which is not able to replace for 99 to 101.could you please help me on this .what was an issue i am not able to find it. If you know the reason or answer let me know

What is your end goal here? Are you looping this request over some set? Are you running iterations against a csv?

Are you always changing the ChannelId to a static value? There might be a way to do what you’re trying to do, it’s just a little unclear with the information you’ve provided so far.

@allen.helton i am trying to replace value for channelId but I am not able to replace. I am seeing only issue with 99,100,101 values .if I put other than 99 to 101 i can able replace the values in the request using prerequisite script.ChannelID always be static I want to replace with some other values instead of above mentioned values. Could you please suggest any solution for this.

Can you please post some screenshots or something? Do you have one block of JSON that contains all these objects? Or is this multiple requests?

@allen.helton i took some screenshot

Request:channel 101 and name OBE

Prerequisite script to replace channel ID with 401 and name:MBE but MBE got replaced.401 not get replaced

Console output for replacement of values MBE got replaced but 401 not replaced with Channel id 101

I tried with different request which has channel ID is 1201 and channel name: MYRES
Not able to paste request screenshot due to some restriction but only changes in request with channel id 1201 and name as MYREs

Executing with same prerequisite script

Got replaced with different channel ID expect 101

Could please help me with that solution.i don’t know how to replace values for channel id 101…which not able to replaceable in postman I tried much

I’m still a little unclear on why you’re programmatically replacing a hardcoded value with another hardcoded value, but I’ll let that go.

I think your issue is that you’re trying to do a string replace on a stringified JSON object. The way you’re replacing the value will only replace the first instance it finds.

Since you’re trying to replace the value 401 there is likely a 401 somewhere in the string before the ChannelId property. I can see that you have a 101 contained in the ID in your last screenshot, so that’s likely is what was replaced by your replace statement.

image

You’d definitely have better success if you manipulated the JSON directly instead. What you’re doing now is unsafe and not guaranteed to change the value you want, which is why you’re seeing this behavior.

@allen.helton i am trying to replace channel id 101 with 401 but it is not replacing the value.you check the last screenshot which is not replacing the values
1st screenshot is request
2nd is prerequisite script
3rd screenshot after replacement request body from the postman console