cancel
Showing results for 
Search instead for 
Did you mean: 

how to pass variable directly in the Value from the Request body

Highlighted
Occasional Contributor

how to pass variable directly in the Value from the Request body

Hi I am trying to parameterize values directly to the body of the message instead of doing the select variable  and selecting the from the variable list. I tried something like {"docId":"idnumber::@getnumber"} where 'getnumber' is my defined variable. If i use that in the request body directly, it is not converting it. Can anyone help?

5 REPLIES
Community Hero

Re: how to pass variable directly in the Value from the Request body

Hi,

 

I tried to paste your sample JSON into the body of some request and got the following:SampleJSON.png

It is my understanding that you like to use the value of the 'getnumber' variable (say, it equals to 5) to get this:

idnumber::5

as the value for the Value field.

If the above screenshot corresponds to your real request and my understanding is correct, then, unfortunately, variable substitution in the middle of the parameter's value is not supported in LoadComplete yet.

I use the following approach when I need to implement something like you need:

-- Create a helper variable and name it, say, getnumberAux ;

-- Add the 'Set Variable Value' operation before the first request that needs the data from the getnumber variable and setup operation like this:SampleSetVariable.png

 

 

-- Now use the getnumberAux variable to replace the recorded value of the request with the modified value:SampleJSON2.png

 

 

Does this help?

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Occasional Contributor

Re: how to pass variable directly in the Value from the Request body

Hi 

thank you for helping out. I tried the way you have mentioned but I am getting error in the response, which look something like this; Also i have attached the screenshot of how I have set it up. Please let me know if you if I had done something differently.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>Error</title>

</head>

<body>

<pre>SyntaxError: Unexpected token C in JSON at position 11<br> &nbsp; &nbsp;at JSON.parse (&lt;anonymous&gtSmiley Wink<br> &nbsp; &nbsp;at pars

 

 

 

Community Hero

Re: how to pass variable directly in the Value from the Request body

Hi,

 

Screenshots look OK.

I would recommend to Verify the scenario (button with green triangle in the Scenario Editor). This will execute the scenario for one virtual user and all data for requests and responses will be logged. Then navigate to the failed request in the log and check if the structure of the JSON been sent corresponds to the structure of the recorded one.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Occasional Contributor

Re: how to pass variable directly in the Value from the Request body

HI Alex,

So the reason why it was not working was, in set variable we were using the quotes. I removed the quotes on the starting and the ending of the expression and it worked fine.  thanks much for your help

Community Hero

Re: how to pass variable directly in the Value from the Request body

Hi,

 

Thank you for the update. Great to know that things are working for you now.

 

> I removed the quotes 

In this case, one concat() function should be enough, though I am pretty sure that you've already did it this way Smiley Happy

 

P.S. I created a new feature request: https://community.smartbear.com/t5/LoadComplete-Feature-Requests/Make-it-possible-to-use-variables-w... and you are welcome to comment / vote.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Share Your Stories
Read Latest News
Top Kudoed Authors