Updating a Property from Javascript

Primary tabs

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"

&js<

    alert(zenPage.currentTableRow);
>

 

Replies

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"
&js<alert("zenPage.ExportQuery="+#(%page.currentTableRow)#);>

}

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)
&js<alert("zenPage.ExportQuery="+#(str)#);>

 

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.

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

&js<

#(%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 %ZEN.Component.page this should work:
Method MyMethod() [ ZenMethod ]
{
    // Within ZEN Pages
    // Set with client code

   &js<
      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
   &js<
      zen(
"#(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!