cancel
Showing results for 
Search instead for 
Did you mean: 

How to Ignore null values in the POST Request

SOLVED
Highlighted
Contributor

How to Ignore null values in the POST Request

Hi

 

Below is my sample request for the POST Request,  in the below request some times the table name values comes as empty or null, so while sending the request i want to ignore this null or empty values, is there a way in readyapi where we can ignore?

 

 

 

{
"tables_list" : [
"${#TestCase#Table1}",
"${#TestCase#Table2}",
"${#TestCase#Table3}",
"${#TestCase#Table4}",
"${#TestCase#Table5}",
"${#TestCase#Table6}",
"${#TestCase#Table7}",
"${#TestCase#Table8}",
"${#TestCase#Table9}",
"${#TestCase#Table10}",
"${#TestCase#Table11}",
"${#TestCase#Table12}"
],

23 REPLIES 23
Highlighted
Community Leader

@doubtsreadyapi : Could should like below

 

StringBuilder sBuild = new StringBuilder();

if (respvalue== null)
{
testRunner.testCase.testSuite.testCases["Post_Dags"].removeProperty("Table1");
}
else
{
testRunner.testCase.testSuite.testCases["Post_Dags"].setPropertyValue("Table1",respvalue)
// Do this in where ever you are storing value
sBuild.append("\${#TestCase#Table1},")
}

if (respvalue== null)
{
testRunner.testCase.testSuite.testCases["Post_Dags"].removeProperty("Table2");
}
else
{
testRunner.testCase.testSuite.testCases["Post_Dags"].setPropertyValue("Table2",respvalue)
// Do this in where ever you are storing value
sBuild.append("\${#TestCase#Table2},")
}

if (respvalue== null)
{
testRunner.testCase.testSuite.testCases["Post_Dags"].removeProperty("Table3");
}
else
{
testRunner.testCase.testSuite.testCases["Post_Dags"].setPropertyValue("Table3",respvalue)
// Do this in where ever you are storing value
sBuild.append("\${#TestCase#Table3},")
}

//and so on



//at the end of the script write this line
String str = sBuild.toString()
//to remove last , from string
str = str.substring(0, str.length() - 1)
testRunner.testCase.setPropertyValue("data_to_use",str);

Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Contributor

@HimanshuTayal 

 

Thanks for the detailed explanation, now the tables are coming with out null, where as the each table must come in quotes, like example, while sending the request the table list must be in below format.

 

"Table1",
"Table2",
"Table3",
"Table4"

 

Where as now request its going as "Table1, Table2, Table3, Table4" Because of that still the backend jobs are failing.

 

is there a way where we can send the request in the below format.

 

"Table1",
"Table2",
"Table3",
"Table4"

 

Thanks in Advance,

 

Thanks

Highlighted
Community Leader

@doubtsreadyapi  You can try like this 

 

sBuild.append("\"\${#TestCase#Table1}\"")

 

hope it will work. 🙂


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

Highlighted
Contributor

@HimanshuTayal 

 

Thanks it's working fine now.

New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Want a fun and easy way to learn ReadyAPI and show off your skills? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Get a full Raw JMS request

Participate!

Compare an expected JSON value and actual response in Events

Participate!

Fetch value/data from JSON response using Groovy Script

See replies!

Get data from Petstore and add it to Excel sheets

Participate!
Top Kudoed Authors