Split is suddenly not recognised as a function

Hi,

I have a string.split line in my postman test which has been working fine until today:
“LocaleArch = pm.environment.get(“bucket3”).split(”,");"

, in fact until late this morning, when I am suddenly being informed:
“TypeError: pm.environment.get(…).split is not a function”

What could have happened?
How do I get back to my happy state that split gave me?

@GIGAMAC

try …

LocaleArch = (pm.environment.get("bucket3")).split(",");

nope - sorry - same pain, but thanks for the tip - it looked sensible…
The only thing I can think of is a change of javascript use by postman somehow.
I started using regexstr.exec() and some other functions I hadn’t used today, and from today the way i can work with strings seems to have changed along with that - I was working more in line with the reference material in mozilla, and now its more like the reference in ww3 schools…

dont know if this makes sense…

@GIGAMAC

I am using split in some of my tests so I went back and looked at how I am using it …

var new_titles = pm.environment.get("newTitles").toString().split(',');

I just ran the test and it’s working just fine.

Also, you might want to check your version of newman … > newman -v

Mine is … 3.9.3

2 Likes

I don’t know if postman is running Newman under its covers (it doesn’t look like it but tbh I am not savvy like that), but I tried this and it worked fine - thanks!

(Given Newman came into the conversation I will look it up and pay more attention to it - thanks also)

Hi! Had the same problem. All work with the single request but throw Type Error in Collection run.
For such code.

let betsString = pm.environment.get("bets");
let betArr = betsString.toString().split(',');

After update to v6.0.10 was the same problem. But there was such message in console “Could not find on CollectionStore. Missing or invalid parameter.”

Then I save this request like a new one and delete old. And all works now. Don’t know where the problem was exactly but probably it will help someone. :grinning:

@o.haistruk Maybe the value is not string. Can you try this

console.log(typeof pm.environment.get('bucket3'))

Does it print string? I guess not.

I haven’t done that, but its a fair shout - would be worth a try as a debug step for when a problem occurs. Further,m typeof isn’t obviously available when you trawl through postman documentation, which by the way blows hot and cold for me.

My problem was though that the postman script behaviour had changed - it was working fine then it stopped working and I had to rethink - given I had typed the variable in by hand every time, the fact that it wasn’t being INTERPRETED as an array where it had been previously was a behaviour change, so I had to change the test instruction to deal with it.

Just to add - Both postman and Newman uses common code to run collections.

@postman-harryi3t Yes! You are right. it was not string. I thought that it is string probably because of view in environment variables panel.

ok I need to add to this now…
I started using myArray = pm.environment.get(“varname”).toString().split(“,”);
as this worked for me on my machine (Mac) in the workspace window, and in a collection run using the environment variables.

A colleague used this same collection and got different results on his (Windows) machine such that:

  • Running from workspace was fine
  • Running as a collection using the same environment causes a run halt and undefined error.
    There is clearly an inconsistency.
1 Like

It works. Thank you.

1 Like

Glad it helped - u r welcome