title: Adding javascript function to jMeter
body: <p>I am trying to get a javascript function work with jMeter test plan.<br>
  It is used to decode a string.</p>
  
  <pre><code>function decode(str) {
      var strtodecrypt = str.split("-");
      var msglength = strtodecrypt.length;
      decrypted_message = "";
      for (var position = 0; position &lt; msglength; position++) {
          ascii_num_byte_to_decrypt = strtodecrypt[position];
          ascii_num_byte_to_decrypt = ascii_num_byte_to_decrypt / 2;
          ascii_num_byte_to_decrypt = ascii_num_byte_to_decrypt - 5;
          decrypted_byte = String.fromCharCode(ascii_num_byte_to_decrypt);
          decrypted_message += decrypted_byte;
      }
      return decrypted_message;
  }
  </code></pre>
  
  <p>I have tried to use BSF Post processor, but don't know what is the exact syntax i need to use. I want to use this function to post a jMeter variable as a parameter in one of the HTTP request.</p>
  
  <p><strong>Edit:</strong>  I am currently using following script in the BSF post processor. <code>userResponse</code> does not show in debub sampler. Do i need to add any reference to use <code>String.fromCharCode(ascii_num_byte_to_decrypt)</code>?</p>
  
  <pre><code>var str="142";
  var strtodecrypt = str.split("-");
  var msglength = strtodecrypt.length;
  decrypted_message = "";
  
  for (var position = 0; position &lt; msglength; position++) {
      ascii_num_byte_to_decrypt = strtodecrypt[position];
      ascii_num_byte_to_decrypt = ascii_num_byte_to_decrypt / 2;
      ascii_num_byte_to_decrypt = ascii_num_byte_to_decrypt - 5;
      decrypted_byte = String.fromCharCode(ascii_num_byte_to_decrypt);
      decrypted_message += decrypted_byte;
  }
  
  vars.put("userResponse",decrypted_message);
  </code></pre>