0

Can this randomString(length) be reused in another pre-request script instead of having in each API request in postman?

function randomString(length){
  var char ='';
  while(chars.length < length ){
    chars += Math.random().toString(36).substring(2);
  }
  returns chars.substring(0,length);
};
Ashok
  • 2,846
  • 1
  • 12
  • 20
Lakshmi
  • 17
  • 1
  • 6

2 Answers2

0

Put it in the pre-script for the collections, it will then run before every request.

madhukar93
  • 507
  • 5
  • 23
-1

You can store the function in an environment variable and then use the eval() function.

Christian Baumann
  • 3,188
  • 3
  • 20
  • 37