Re-using session variable as a patern parameter
I'm trying to basically search for the session variable in a load of text that i'm trying to extract. Would somethnig like this work:
name="ProductID" value="~@SKU@~" />
Basically I have a load of size variables that all look the same with the same markups. I need to search for the size that I have got saved as a session variable and then search for the SKU using the known size var form the variable.
So in pratice:
session.varibale = size 12
I need to transpose the session variable into the ~#size_var#~ and use this as the seatch pattern, so it will return the SKU for the correct size.
Because I get similar
Because I get similar questions once in a while, I made up a FAQ on this.
Thnaks for the lnik.
Thnaks for the lnik. Strugglnig to write my scrip tthough, keep getting issues with the else statements. Also got issues with trying to run a null value into the equals field hence these changes:
{
if (session.getVariable("size")!="");
{
if (dataRecord.get("new_size").equals( session.getVariable( "size" ) ) );
{
out.write( dataRecord.get( "size_SKU" ) + "|" );
}
else
{
out.write( dataRecord.get( "SKU" ) + "|" );
}
}
}
I'm not sure why you're
I'm not sure why you're dealing with empty Strings here. I would think this would be the way to go:
newSize = dataRecord.get("new_size");
if (newSize!=null && !newSize.equals(""))
{
// newSize is valid
desiredSize = session.getv("SIZE");
if (desiredSize!=null && !desiredSize.equals(""))
{
// See if newSize is desiredSize
if (newSize.equals(desiredSize))
out.write(dataRecord.get("size_SKU") + "|");
else
out.write(dataRecord.get("SKU") + "|");
}
else
session.log("No desiredSize");
}
else
session.log("No newSize");