jscript SetVar - Forum

Forum Navigation
You need to log in to create posts and topics.

jscript SetVar

i have jscript func that parese json like this

json = '{"result":true, "count":42}';
obj = JSON.parse(json);

and when i try to get the parsed json as var with this

publication.nbSetVar "[%1]", obj.count

the error hapend and say ! Expected ';'

i also add ; end of code

publication.nbSetVar "[%1]", obj.count;

still same error but the publication.nbSetVar is work in vbscript correctly

may be in jscript must do some thing elese

let me know how its must be

@victor the problem you are describing is a bit difficult to understand. Can you please share a simple app showing the problem?
Thank you!

victor has reacted to this post.
victor

yes i upload test app and the functions file

simply its is a jscript json parser and the script tested in nodejs and had no error

only error i get is when try to get resault of prsed json as variable in visualneowin

 

( btwy if there is any better way to parse json in visualneowin let me know im using external cmd app for parse json ( like JQ ) but its slow down the project )

 

tnks for help :)

Uploaded files:
  • You need to login to have access to uploads.

@victor I think you should consider using this awesome plugin:

https://tropicdesigns.net/ezjson-plugin.html

Regards.

victor has reacted to this post.
victor

ok tnk you it seems good plugin

and what about that jscript?

i mean i get error even on other jscripts not only this one when i try to use publication.nbSetVar

can u give me an example to use publication.nbSetVar in jscripts

because in vbscripts work witout problem but in js i get error say [! Expected ';']

and tnks for helping this

@victor

and what about that jscript?
i mean i get error even on other jscripts not only this one when i try to use publication.nbSetVar
can u give me an example to use publication.nbSetVar in jscripts

Here is a demo javascript function that takes a number passed as the first parameter in a Call command, adds one to it, and stores the result as a VNWin variable ... and then displays this variable (using AlertBox) from within the javascript function.

// showcase to get, set and execute in javascript functions
function jsGetSetExec(a){
var b = a+1;
nbSetVar("[gk]",b);
nbExecAction('AlertBox "b=" "[gk]"');
}
jsGetSetExec([inputNumber]);

In the Function parameters section, please add ...

Alias: [inputNumber]
Type: Number
Description: number passed as input

You can name this function file whatever you desire; just use the same name as the first parameter in your Call command.

luishp and victor have reacted to this post.
luishpvictor

@victor

because in vbscripts work witout problem but in js i get error say [! Expected ';']

I think it is because javascript (unlike vbscript) does not support a count method ... there are a few examples on the internet that show how you can get a count of the number of key/value pairs in a JSON object ... if you can not find them (using Google search), just holler and I will post links.

victor has reacted to this post.
victor

@victor

Another example that also demos nbGetVar ...

a) attach this code to a button ...

SetVar "[gkStringIn1]" "abcd"
SetVar "[gkStringIn2]" "wxyz"

Call "jsDemo2"

AlertBox "gkStrinOut" "[gkStringOut]"

b) make this content of function file jsDemo2 ...

// showcase to getVar and setVar in javascript functions
jsInput1 = nbGetVar( "[gkStringIn1]" )
jsInput2 = nbGetVar( "[gkStringIn2]" )

jsOutput = jsInput1 + "..." + jsInput2;
nbSetVar("[gkStringOut]",jsOutput);

 

luishp and victor have reacted to this post.
luishpvictor

Tank You Very Much

The Examples Solve My problem

Very Good To Have You Here :))