Parameterization in Java vuser protocol is not working

Hi Experts,

I am trying to parameterize a value in Java Vuser protocol but it is not replacing as expected.

Eg. I have parameterized recordNbr as shown below in my script

String recordNumber="{p_recordNbr}"

System.out.println(recordNumber);

String messageStr="{\n\t \"leadiLoadHeaderId\": \"12345\",\n\t \"recordibr\":\{p_recardNbr}\",\n\t \"firstName......

// Here is the response I am getting. It's not replacing with parameter value but just print parameter name as below

// System.err: System.out: {p_recordNbr}
// System.out: {
//  "leadLoadHeaderId": "12345",
//  "recordNbr":"(p_recordNbr}",
//  "firstName": "abcdName",
//  "lastName": "xyzName",

Could anyone help to fix this issue ?

[EDIT] Put code in code block

  • Verified Answer

    +1  

      ,

    In LR parameter are replaced in strings when they are used in a certain context. E.g. certain arguments of lr.* or web.* functions. Consult the LRP help and look for a section called PARAMETERIZATION.

    When you want to resolve parameters in other places you have to call explicitly to do so: see lr.eval_string(). E.g,:

    String recordNumber = lr.eval_string("{p_recordNbr}")

    Be careful with 'final' and 'static' Strings in combination with lr.eval_string().

    How to ask questions

    Reward contributions via likes or 'verified answers'

  • 0 in reply to   

    Nothing worked. Especially i want to replace value in messageStr but it's not happening while using LR.eval_string. 

    String recordNumber= Ir.eval string({p_recordNbr}");

    String record Number="{p_recordNbr}";

    System.out.println(recordNumber);

    String messageStr="{\n\t \"leadLoadHeaderId\": \"12345\", \n\t \"recordNbr\":\"(p_recordNbr}\",\n\t \"firstName\":\"abcName.....

    System.out.println(messageStr);

    Output:

    Actions.java(19): Notify: Parameter Substitution: parameter "p_recordNbr" "33447"

    System.out: {p_recordNbr}

    System.out: {

    "leadLoadHeaderId": "12345",

    "recordNbr": "(p_recordNbr)",

    "firstName": "abcName",

  • 0 in reply to   

    It's working even after using le.eval_string. but how to replace in messageStr. Can we write eval function directly? But it's not working or can we use variable recordNumber ? Could you suggest 

    String recordNumber =Ir.eval string("{p_recordNbr}");

    System.out.println(recordNumber);

    String messageStr="{\n\t \"leadLoadHeaderId\": \"12345\", \n\t \"recordlibr\":\"lr.eval_string("{p_recordNbr}"\, \n \t \"firstName\": \"abcName\"......

    System.out.println(messageStr);

    );

    Here is the output

    Actions.java(19): Notify: Parameter Substitution: parameter "p_recordNbr" "33447"

    System.out: 33447

    System.out: {

    "leadLoadHeaderId": "12345",

    "recordNbr" : "lr.eval_string("{p_recordNbr}")"

  • 0

    Thanks it worked 

  • 0   in reply to 

    Nice, you discovered that you cannot use method-calls inside a String, like you can in Python with f-strings Slight smile

    How to ask questions

    Reward contributions via likes or 'verified answers'