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:
<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,
Try commenting out all write statements in sqlTest method.
Thank you Eduard!
Now it works. This is the code:
My only comment is that the -not working- code a (100%) sample is from the documentation, which makes it sometimes confusing...
Thanks.
Where exactly in samples?
This was the code snippet I have used:
I am now looking how the get a "No data returned" message into my Form
It's a valid sample. You just can't write directly into ZEN context. Well, you can, obviously, but that causes errors.
I would like to return a "No Data message" but why does the write statement not work?,
while the documentation is full of examples with the statement in it?
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.
SQLCODE=100
would be a codepath for no data.
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
}