Question
· Mar 25, 2017

Javascript exception

Hi community,

I do not understand why I get a 'javaScript exception'?

 

Purpose is to search for a [Country] based upon a [Code] as search parameter.

this is my code:

<hgroup>
<text id="CountryID" name="Code" label="Code" size ="8" />
<spacer width="5"/>
<text id="CountryName" name="CName" label="Country" size ="24" />
</hgroup>
<spacer height="5"/>
<button caption="Search" onclick="zenPage.searchValue();"/>

</page>
}

ClientMethod searchValue() [ Language = javascript ]
{
var ctrl zen('CountryID');
tVar ctrl.getValue();
alert (tVar); ///test-show text value
zenPage.sqlTest(tVar);
}

Method sqlTest(tVar) [ ZenMethod ]
{
SET InVal = tVar
   &sql(SELECT Countrie
        INTO :OutVal
        FROM ZenCrm_Data.Countries
        WHERE CountrieCode=:InVal)
   IF SQLCODE'=0 SET OutVal="?" 
      IF OutVal="?" {
      WRITE !,"No data returned"
      WRITE !,"SQL error code ",SQLCODE }
   ELSE {
   WRITE !,"Name is: ",OutVal}
}
 

Does the method needs a 'Return' statement ore something?

Can somebody explain please? this might help me with other programming issue's to!

Thanks in advance,

Discussion (9)0
Log in or sign up to continue

Write statement does what it's name implies - outputs characters into a current device. It's a way to go if you're working from a terminal, but ZEN does it's own device management, so writing into a current device interferes with ZEN also writing into current device, which causes an error.

 

To make it work check if there's no data (SQLCODE=100) and set OutVal to empty (or error message) and work with that on a client.

Hi Marco,

You can do with QUIT, to take back the value in javascript and work with it:

ClientMethod searchValue() [ Language = javascript ]
{
var ctrl zen('CountryID');
tVar ctrl.getValue();
alert (tVar); ///test-show text value

///example
name = zenPage.sqlTest(tVar);

zen('CountryName').setValue(name);
}

Method sqlTest(tVar) [ ZenMethod ]
{
SET InVal = tVar
   &sql(SELECT Countrie
        INTO :OutVal
        FROM ZenCrm_Data.Countries
        WHERE CountrieCode=:InVal)
   QUIT:SQLCODE'=0 "No data returned! \n SQL error code "_SQLCODE
   QUIT "Name is = "_OutVal
}