JSR223 Sampler - Pass external results back to JMeter
Here is how to communicate with the JMeter framework from the script code.
SampleResult.setResponseCode("300");
SampleResult.setSuccessful(false);
SampleResult.setErrorCount(2);
SampleResult.setResponseData("This is the response");