cancel
Showing results for 
Search instead for 
Did you mean: 

How to Ignore null values in the POST Request

SOLVED
Highlighted
Community Leader

Re: How to Ignore null values in the POST Request

@doubtsreadyapi :

 

Sorry, but i didn't understand completely, could you please share code snapshot for more clarity.

 


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



Thanks and Regards,
Himanshu Tayal
Highlighted
Contributor

Re: How to Ignore null values in the POST Request

Hi @HimanshuTayal 

 

Step1 : In JDBC connection step i am getting list of tables. 

Step2: i am using below sample code to pick the random table using the JSON Node.

 

def resp1=new XmlHolder(resp)
def respvalue =resp1.getNodeValue('/Results/ResultSet/Row[1]/*')
log.info respvalue
if (respvalue== null)
{
testRunner.testCase.testSuite.testCases["Post_Dags"].removeProperty("Table1");
}
else
{
testRunner.testCase.testSuite.testCases["Post_Dags"].setPropertyValue("Table1",respvalue)
}

 

In Step 3 which is Post payload i am calling the Table1 from Custom property

 

{
"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}"
]

}

 

As i mentioned earlier Some times in the JDBC response, the table names may come as empty or null, So in the POST payload which ever the table name value is null must be ignored while posting the request.

 

Hope this is understandable.

 

 

Community Leader

Re: How to Ignore null values in the POST Request

@doubtsreadyapi :

 

Yes, now it's clear, thanks, so what i would suggest is create your request for Step 3 at step 2 level, how you can proceed is :

 

1. Declare a variable with StringBuilder and append all the Table in that, then store it in some variable.

2. Pass that variable to your 3rd step.

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},")
}

//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);

 

 

In Step 3, just use below

 

{
"tables_list" : [
"${#TestCase#data_to_use}"
]

}

 

Hope it will work for you 🙂

 


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



Thanks and Regards,
Himanshu Tayal
Highlighted
Contributor

Re: How to Ignore null values in the POST Request

@HimanshuTayal 

 

Thanks for the update.. this works only for one table, what about if i have multiple tables? 

 

 

Highlighted
Community Leader

Re: How to Ignore null values in the POST Request

@doubtsreadyapi : It all depends on how you are fetching data from different table, could you please attach code or code snippet that how you are fetching data from different table.

 

So that i can help further 🙂


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



Thanks and Regards,
Himanshu Tayal
Highlighted
Contributor

Re: How to Ignore null values in the POST Request

@Himanshu,

Thanks for the update.. i am not fetching the data from the tables, using jdbc connection i am getting list of table names and using groovy and using the json nodes of the jdbc connection response i am storing some table names in custom variables.. and i am using this custom variables in the post request by using get data options

I am storing 10 table names in custom variables. So the problem is some times the json nodes which i am using may not be available in response.. because of that in custom variables doesnt contain any value for that.. so in post since we are using that custom property.. and when request is sent its going as null or empty..bcoz of that the backend jobs are failing.

Hope this clears.
Highlighted
Community Leader

Re: How to Ignore null values in the POST Request

@doubtsreadyapi : Then if i am not wrong you are having 10 JDBC Connection and 10 Groovy script step to fetch data from DB and then storing it to custom properties.

 

If this is the case then you can write the same code in last groovy step by doing some changes.

 

If i haven't understood it correctly could you please attach any screenshot of how you are doing this.


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



Thanks and Regards,
Himanshu Tayal
Highlighted
Contributor

Re: How to Ignore null values in the POST Request

@Himanshu

You are almost correct..where as i am using only one jdbc connetion.. in that jdbc connetion only i will get list of table names.

Yes i am using groovy script to pick the random table names using the json nodes from thr jdbc response.

I used the code you provided.. but its picking only table.. though i have 10tables storing in custom variables

Thanks
Highlighted
Community Leader

Re: How to Ignore null values in the POST Request

so i suppose you groovy code will be like this:

 

 

def resp1=new XmlHolder(resp)
def respvalue =resp1.getNodeValue('/Results/ResultSet/Row[1]/*')
log.info respvalue
if (respvalue== null)
{
testRunner.testCase.testSuite.testCases["Post_Dags"].removeProperty("Table1");
}
else
{
testRunner.testCase.testSuite.testCases["Post_Dags"].setPropertyValue("Table1",respvalue)
}

 

 

 

def resp2=new XmlHolder(resp)
def respvalue =resp2.getNodeValue('/Results/ResultSet/Row[2]/*')
log.info respvalue
if (respvalue== null)
{
testRunner.testCase.testSuite.testCases["Post_Dags"].removeProperty("Table2");
}
else
{
testRunner.testCase.testSuite.testCases["Post_Dags"].setPropertyValue("Table2",respvalue)
}

 

 

 

def resp3=new XmlHolder(resp)
def respvalue =resp3.getNodeValue('/Results/ResultSet/Row[3]/*')
log.info respvalue
if (respvalue== null)
{
testRunner.testCase.testSuite.testCases["Post_Dags"].removeProperty("Table3");
}
else
{
testRunner.testCase.testSuite.testCases["Post_Dags"].setPropertyValue("Table3",respvalue)
}

 

 

and so on am i correct,

 

if this is the case then you can write my code and every else condition you can write 

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

this will solve you isue. 


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



Thanks and Regards,
Himanshu Tayal
Highlighted
Contributor

Re: How to Ignore null values in the POST Request

Hi @Himanshu

Yes my groovy code is same what u have posted.

You mean to say i have to use below code in my groovy script? And change the table name accordingly?

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},")
}

//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);

I tried using ur code but i was getting compilation errors saying sbuild is already used, so i changed for ever table as sbuild1, sbuild2 and so on,

But still it was picking only one table
Please let me know if i am doing anything wrong

And at the end of the script also u want me to write for each table? And change data_for_use also for each table?

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors