problem using web_js_run() function

HI all,

i am calling a code.js file through web_js_run() function. Basically i want to pass a string which will be encrypted by javascript.

I am trying below function

web_js_run(
    "Code= encrypt('SampleString')",
    "ResultParam=param1",
    SOURCES,
    "File=code.js", ENDITEM,
    LAST);

And i am getting proper encrypted string. As soon as i replace it wth variable it stops working. error is "var1 is not defined"

web_js_run(
    "Code= encrypt({Var1})",
    "ResultParam=param1",
    SOURCES,
    "File=code.js", ENDITEM,
    LAST);;

I tried another way,

char *tmp=lr_eval_string("encrypt({var1})");

web_js_run(
    "Code= {temp}",
    "ResultParam=param1",
    SOURCES,
    "File=code.js", ENDITEM,
    LAST);

The above code is also giving me error " temp is not defined"

Please not that "var1" is the data which i need to pass trough csv file which i have declared in parameters.

 

 

  • Verified Answer

    with some trial n error i got the solution.

     

    web_js_run(
        "Code= encrypt('{Var1}')",
        "ResultParam=param1",
        SOURCES,
        "File=code.js", ENDITEM,
        LAST);

  • I want to convert a value into HTML to URL and need to pass html value as a parameter.

    Solution 1: without passing parameter

    web_js_run("Code=EncURI(\"670523   X\");",
            "ResultParam=EURI",
            SOURCES,
            "Code= var EncURI = function(uri) { return encodeURI(uri);}", ENDITEM,
            LAST);

    Output: 

    Action.c(12): web_js_run was successful [MsgId: MMSG-26392]
    Action.c(16): web_js_run started [MsgId: MMSG-26355]
    Action.c(16): Notify: Saving Parameter "EURI = 670523 X".

     

    Solution 2: passing with a parameter

    step1: Create a parameter called "enc" and pass the parameter using LR.getParam.

    Step2:

    web_js_run("Code=EncURI(LR.getParam('enc'));",
            "ResultParam=EURI1",
            SOURCES,
            "Code= var EncURI = function(uri) { return encodeURI(uri);}", ENDITEM,
            LAST);

     

    output:

    Action.c(12): web_js_run was successful [MsgId: MMSG-26392]
    Action.c(16): web_js_run started [MsgId: MMSG-26355]
    Action.c(16): Notify: Saving Parameter "EURI = 670523 X".

     

     

  • I tried executing the web_js_run() function.

    I called the javascript file by adding to the extra file.

    web_js_run(
    "Code=httpgetAsync(theURL,callback)
    "ResultParam=test",
    SOURCES,
    "File=filenamewithjavascript.js", ENDITEM,
    LAST);

    error message:

    error from js engine : javascriptfilepath\filename.js:1:Syntax error : missing = in XML attribute.

    note: The javascript has the whole javascript including tags.

  • You code example looks OK, but did you made a source copy error? You list

    "Code=httpgetAsync(theURL,callback) but it should be "Code=httpgetAsync(theURL,callback);" Missing ; and closing ".

    Any way the error seems to indicate a JS-source script parsing issue. So validate the JS source code with an other tool.

  • Yeah @jhfremmelzwaal, I have just added the function via the function dialog of web_js_run(). The problem is , I was suggested to include the JSfilename.js in the global.h file as # include "JSfilename.js" but on adding the same, the system started throwing the compilation issue.

    Do you have any other better suggestions to try out.
  • When you are using #include <filename> the filename should contain c-code and not JS-code. So you should remove that line of code.

    You should add your JS-lib file as file under 'Extra Files' in your solution and name it in your web_js_run() call. That should be sufficient.


  • I have also added the filename.js under extra files and then removed the #include" <filename>.js" line under the global.h file of extra file.
    Output:
    Missing = in XML attribute.

    Note : the JS file will have the &lt;script&gt; tag.
  • Can you post the js-file here as an attachment? It should be a valid JS-file. You might try to analyze its content via online JS-coding side or alike.