2

Have a dynamic value stringval How to extract values from it and store it in 3 different variable separated by pipes (|)

stringval ="A|B|C"

want to store these value separately in three different variables like Var1(value for A), Var2 (value for B), Var3 (value for C) . Let me know how to do it.

[
  {
   "Fieldid": "Fieldid/11",
    "fieldName": "TX.Sessionval.cost",
    "**stringval**": "jklah-dw-4c8d-8320-das313s3ASsda|000725N8WuUrfmIsbj!AS7alP|Danny_username"
  }
]

How to print only 3 Env variables? as mentioned in comment, need only 3

1

1 Answer 1

1

I would have thought you would need to get the value first:

let str = pm.response.json()[0].stringval

Then split that on the pipe:

let value = str.split('|')

Then store the values as variables:

pm.environment.set('value_1', value[0])
pm.environment.set('value_2', value[1]) 
pm.environment.set('value_3', value[2]) 

I've not run any of this so I would take each thing at a time and log it to the console to ensure that it's captured the right data points before putting it all together.

Sign up to request clarification or add additional context in comments.

5 Comments

adding to it .. for printing each value with and for rest of 3 values same way for 'value_1' console.log(pm.variables.get("value_1"))
You could show all 3 in the console by using console.log(pm.environment.toObject())
This will return all the variables in environment. only wanted newly created (val0 - val3)
Easy to filter that based on what the variable starts with 😂 - Many ways to do the same thing, you don't always have to add multiple statements that look the same 😁 Same can be said with the way I have set them in the answer.
Can we search this stringval ="A|B|C" from whole list and save it, new fields will be added in Json arraylist stackoverflow.com/questions/64145717/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.