Arnold Cota · May 26, 2020

Updating a Property from Javascript

I am trying to set a varaible/property within JavaScript and use the value in my method.  The alert method below returns "0".  Do I have the syntax wrong?

/// Storage for current table row

Property currentTableRow As %ZEN.Datatype.string [ InitialExpression = 0 ];

set ..currentTableRow = "1"




3 0 8 222
Log in or sign up to continue


Thanks Jean, will check this out

Arnold, it could be a scope problem / zen expression problem.

Try something like this:

Property currentTableRow As %ZEN.Datatype.string(MAXLEN = 5000);

Method MyMethodOnServer() [ZenMethod] {

set %page.currentTableRow="1"


I had trouble with a longer string. For a string that's not a number, try this:

set %page.currentTableRow="line 1"

set str=..QuoteJS(%page.currentTableRow)


Nice! This worked for me.  I removed the (MAXLEN) and it still worked.  I am not sure how big my string will be, but I have enough to move forward.  Thank you!

Definitely remove the MAXLEN! I had copied code from my own page, and changed the name of the variable, but not its MAXLEN property. An aside: note that the efault MAXLEN is 50, which I run up against, a lot.   

And do read the documentation that Jean sent out.  I had to read the documentation many times to get it all, and I still go back to it.

Will do, thank you both!

A follow can I set this Property via  JS?  None of these work :(


#(%page.currentTableRow)# = "test"

%page.currentTableRow = "test"

zenPage.currentTableRow = "test"


Make sure that your Cache Method or ClassMethod has the [ ZenMethod ] keyword.

If you're within a this should work:
Method MyMethod() [ ZenMethod ]
    // Within ZEN Pages
    // Set with client code

      zenPage.currentTableRow "test"
  // Set with server code
  %page.currentTableRow = "test"

If you're within a %ZEN.Component.composite and the variable is also within the composite, this should work:
Method MyMethod() [ ZenMethod ]
  // Within Composite Components, here's one way that works as long as your <composite> has an id
  // Set with client code

  S ID =
"#(ID)#").currentTableRow "test"
// Set with server code
$this.currentTableRow = "test"

I left out the ClientMethod versions for brevity, but basically just use 
zenPage.currentTableRow within ZenPages, and this.currentTableRow within Composite Components.

Hope this helps!