0

I searched the community and found questions the are a little bit like mine but i could not find a answer to my question. I think for someone who knows javascript and Postman its easy. So i hope you can help me!

I have two GET Statements which asks a server and set the answer number as variable in my Postman Environment that works fine.

var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("state_server1", jsonData.results[0].attrs.state);

and the same for my other Server. Now i have a PUT Statement which uploads the variable from state-server1 and state-server2 in a CMS that works fine. Now i want to have a if query which checks if the variables state_server 1 === 0 && state_server 2 === 0 are both 0 and create a new variable state_server 12 = No problems!

So the code would be simply in my head likely so:

var state_server 1
var state_server 2
if(state_server 1 === 0 && state_server 2 === 0){
make new variable state_server12 = problems! 

Hope you understand me and you can help me!

klausf11
  • 95
  • 1
  • 2
  • 10
  • check this: http://stackoverflow.com/questions/14465177/multiple-ajax-calls-wait-for-last-one-to-load-then-execute – Abdul Rafay Mar 13 '17 at 10:07
  • then what's error in your code? – Abdul Rafay Mar 13 '17 at 10:18
  • I dont have a error, i just dont know how to set the "new" variable after the if query. – klausf11 Mar 13 '17 at 10:19
  • create a global variable, `var state_server12 = null` and then assign value after `get()` requests. – Abdul Rafay Mar 13 '17 at 10:21
  • Do u mean that way? var state_server12 = null; var state_server1; var state_server2; if (state_server1 === 0 && var state_server2 === 0){ state_server45.get("everything is fine"); } – klausf11 Mar 13 '17 at 10:30
  • no. `var state_server12 = null; if(state_server 1 === 0 && state_server 2 === 0){ state_server12 ='problems'; }` – Abdul Rafay Mar 13 '17 at 10:33
  • With that i'll get this Error: There was an error in evaluating the Pre-request Script: ReferenceError: state_server1 is not defined Does this "script" find the variable state_server1 in the if query? I set it as Environment variable :/ – klausf11 Mar 13 '17 at 10:39
  • add a jsfiddle to debug your code – Abdul Rafay Mar 13 '17 at 10:40
  • I am sorry i dont know what you mean. I am a beginner. In Postman & Javascript – klausf11 Mar 13 '17 at 10:47

0 Answers0