Hi folks, I’ve been using Postman for a couple of years now but I’m only now just delving into creating my own Pre-Request scripts.
I’m using a .json POST request to send data into a SQL database to represent a parcel that contains multiple items. The parcel has its own reference number, but each item needs its own unqiue customer demand reference as well as a unique invoice number.
Previously I would send each customer demand individually, but with the same parcel reference hard-coded, so each time I sent the POST message a new Invoice Number and DemandID would be generated, which was fine. However I now want to be able to create whole parcels at once, so each POST request contains multiples of the same payload within the .json, which means my RNGs are no longer fit for purpose because they generate a random number but then insert the same one into each instance of the payload.
In the Pre-Request script I currently have:
So my question is, is there a way for the Pre-Request script to generate a different invoice number/demand ID multiple times within the same message without resorting to:
I could do it this way, but it kind of defeats the point of the time I’m trying to save.
Hopefully I’ve explained this as best as I can!
Thanks in advance.