Home > other >  Facing error while storing date in a Jemeter variable using beanshell preprocessor
Facing error while storing date in a Jemeter variable using beanshell preprocessor

Time:06-02

I am new to Jmeter and I am facing this issue. The some_date has date like

2022-06-5T10:10:10.12345 

After splitting,
The final_date has only

2022-06-5
String a = vars.get("some_date");
String b = a.split("T");
log.info(b[0]);
final_date = b[0];
vars.putObject("final_sending_date",final_date);
log.info(final_sending_date);

I am getting an error while using vars.putObject

javax.script.ScritException: groovy.lang.MissingPropertyException : No such property :
final_sending_date for class : Script

CodePudding user response:

There is a couple of problems with your script:

  1. String.split() function returns an array of Strings so you need to change second line to:

    String [] b = a.split("T");
    
  2. The final_sending_date object is not declared anywhere, most probably you meant something like:

    log.info(vars.getObject("final_sending_date"));
    
  3. Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting for maximum performance so consider migrating, the same code will work fine without changes in Groovy

Full code just in case:

String a = vars.get("some_date");
String [] b = a.split("T");
log.info(b[0]);
final_date = b[0];
vars.putObject("final_sending_date",final_date);
log.info(vars.getObject("final_sending_date"));
  • Related