Written by

Question Anas Smith · Jun 1, 2024

Calling clientmethod or method from HTM component

Hi guys,

How can call a clientMethod, Method or classMethod from a html component?

I've this hyperlink acting as a button in  a zen page and onclick I've tried the below which is actually executing the function but failing to call the classMethod line, and is there a way to just call clientMethod instead of javascript ? 

   <td><id="btnLast" data-role="button" onclick="getWOs();" href="MyOrders.WO.cls">Last </a></td>
 

ClassMethod retGetWO(wo)
{
Set (WO,Note,Desc,out)=""
if MtcId'=""
{
&SQL(Select  Wo into :WO From Purchace.Order Where id=:wo)
}
WO'="" %session.Data("WO")=WO}

function getWOs()
{
var wo=document.getElementById("WOs4").value
sessionStorage.setItem("sWO", wo);
#server(..retGetWO(wo))#;

}

 

Thanks

Product version: Ensemble 2018.1

Comments

Robert Cemper · Jun 1, 2024

Principal limit: HTML just knows about JavaScript
JavaScript is executing an XHTML call to your Ensemble carrying along all required credentials.
e.g. sessionid,  encryption, cookies, ....
In your namespace SAMPLES zipcode.cls ia a detailed example,
your call looks like this;

#server(..validateZipCode(zipcode))#

But the generated code is this:

("cspHttpServerMethod")_"('"_(..Encrypt($listbuild($classname()_".validateZipCode"))_$select(%session.UseSessionCookie'=2:"&CSPCHD="_%session.CSPSessionCookie,1:""))_"',zipcode)",!

HTML has no idea about all this
 

0
Anas Smith  Jun 1, 2024 to Robert Cemper

Thanks Robert but :

  1. I check Samples & User namespaces in Ensemble 2014 to 2018 and couldn't find zipcode.cls or similar class 
  2. I've check the online docs and find some code but all of them using the old CSP pages and it's working fine in my CSP pages as well but not working in the new Zen pages where its using the Method & ClassMethod call as in my code above not the old eg.
<script language="cache" method="AlertUser">
&js<alert("Hello User");> 
</script>

in CSP pages and my understanding it should be the same for some reason its not working? 
I've some tracing code and actually it's failing at 
#server(..retGetWO(wo))#; line, its not recognizing the syntax which makes me thinks that's only work in CSP pages!? 
Thanks

0
Robert Cemper  Jun 2, 2024 to Anas Smith

Sorry: my typo:   zipcode.csp  generates csp.zipcode.CLS

<script language="cache" method="AlertUser">  
this generates the method.
But your CSP page works with HTML + js in your Browser
to the Browser that interprets and call just as JS.

BTW: old CSP pages
YES, this hasn't changed since it was fresh ~22 years ago (my 1st training docu @ISC)
and NO browser ever accepted ObjectScript as scripting language.
the <script language="cache" ...> tag is just a compiler directive and never reaches  the browser.

0
Anas Smith  Jun 2, 2024 to Robert Cemper

Let me check something first

0
Josephus Flav · Jun 2, 2024

How many CSP pages have you traced in operation before?

You might need to study documentation or take some related training.
 

0
David Hockenbroch · Jun 3, 2024

Are you using a CSP or a Zen page? In one of your comments you mentioned Zen.

That's also not the correct syntax for calling a class method. It would be:

#server(##class(MyOrders.WO).retGetWO(wo))#;

That's assuming this is all in the class MyOrders.WO.

0