Fabiolus
16 years agoOccasional Contributor
Removing Nodes when field is blank
Good day,
I just got my license for the pro version 3.0.1 and did my first script and was trying to add more to it but got stuck. I was wondering if I was in the right direction and if assistance was available. Thank You very much for your help
Bassically my script reads a spreadsheet row by row to send specific values to the WSDL. Some rows are blank and others have data and I was trying to create a groovy script that would remove a specific node when the cell for a specific column in the spreadsheet was blank because it was failing my test.
The script as follow
import java.text.*
import java.io.*;
import java.util.*;
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
//variable length to hold value of the field "LenghtInCm" found in the spreadsheet
def Length = context.expand( '${Read Spreadsheet#LengthInCm(if empty, remove node)}' )
def holder = groovyUtils.getXmlHolder("getDistrOrderRate#Request")
// Length Iff statement to remove node when field in spreadsheet is blank
if ((Length.equals("") == true) || (Length.equals(" ") == true))
{
holder.removeDomNodes("//ord1:LengthInCm");
}
//keep node if value found in the column "LengthInCm" found in spreadsheet.
else
{
holder.setNodeValue("//ord1:LengthInCm", Length);
}//if-else(Length)
I just got my license for the pro version 3.0.1 and did my first script and was trying to add more to it but got stuck. I was wondering if I was in the right direction and if assistance was available. Thank You very much for your help
Bassically my script reads a spreadsheet row by row to send specific values to the WSDL. Some rows are blank and others have data and I was trying to create a groovy script that would remove a specific node when the cell for a specific column in the spreadsheet was blank because it was failing my test.
The script as follow
import java.text.*
import java.io.*;
import java.util.*;
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
//variable length to hold value of the field "LenghtInCm" found in the spreadsheet
def Length = context.expand( '${Read Spreadsheet#LengthInCm(if empty, remove node)}' )
def holder = groovyUtils.getXmlHolder("getDistrOrderRate#Request")
// Length Iff statement to remove node when field in spreadsheet is blank
if ((Length.equals("") == true) || (Length.equals(" ") == true))
{
holder.removeDomNodes("//ord1:LengthInCm");
}
//keep node if value found in the column "LengthInCm" found in spreadsheet.
else
{
holder.setNodeValue("//ord1:LengthInCm", Length);
}//if-else(Length)