View Full Version : Newbie web app developer: data validation
Hi all,
linked to this post https://www.lianja.com/community/showthread.php?4180-Best-data-access, I'm tryng to create some test app for my new ERP.
My first question is:
I can use function like (keylookup('pdc', 'conto', '{}', true, false)) on FormItem data validation?
I think no.. this is Lianja/VFP..
But I can use this code on column data validation into the DB.. right?
thanks
Fabio
barrymavin
2018-06-12, 05:06
Hi Fabio,
Right click on the browser window and inspect it.
Select the console.
Type expressions and look at the results.
keyLookup() is there as is sqlLookup().
Javascript is case sensitive.
Any expressions that cannot be evaluated on the client are evaluated on the server. So you can call your own functions on the server.
https://www.lianja.com/doc/index.php/Data_Validation
Thanks Barry.
this work!
keylookup("semdata!pdc", "conto", "20/01/EMMB", "true", "false")!="false"
Fabio
work on the Inspector, but not work as a data validation.
On the FormItem, I've wryte:
keylookup("semdata!pdc", "conto", "{}", "true", "false")!="false"
but on the preview, the record are not updated... without error.
thanks
Fabio
barrymavin
2018-06-12, 06:48
Try single quotes and learn how to see what network requests are made to see any possible errors.
I don't know where to search any error..
on the inspector:
keylookup('semdata!caucont', 'C_CAUCONT', 'IFAC', 'true', 'false')!='false'
return true..
keylookup('semdata!caucont', 'C_CAUCONT', 'XXXXXXXX', 'true', 'false')!='false'
return true.. but it's wrong..
I'm confused (and ignorant).
Ok, on the debug window, I see something
1700
but why the string are without quotes?
found.. I need to wryte:
keylookup('semdata!caucont', 'C_CAUCONT', "'{}'", 'true', 'false')!='false'
but this work on the inspector, don't work on the Lianha App Builder and don't work on the Lianja Web App View
barrymavin
2018-06-12, 07:09
You still have it in double quotes.
I've try with single and double..
barrymavin
2018-06-12, 07:22
It’s to do with how you are quoting the arguments. I’ll look at it tomorrow. You can quote ‘ by specifying it twice e.g ‘’.
Ok, I've create a simple APP, Javascript, based on SouthWind
I've a section, based on Orders table
I've created a index on customers table
Index on customerid tag customerid
on the customer formfield I've add a validation:
keylookup('southwind!customers', 'customerid', "'{}'", 'true', 'false')!='false'
this work on App Builder but not on Web Preview.
but work on app inspector if I put a value
keylookup('southwind!customers', 'customerid', "WILMK", 'true', 'false')!='false'
I've try with single and double quotes
it's impossible to save the edited records.
Can I use:
Lianja.evaluate("mylib::mylibproc('{}')") ?
yvonne.milne
2018-06-12, 09:06
Hi Fabio,
There are too many quotes around the {}. It should be:
keylookup('southwind!customers', 'customerid', '{}', 'true', 'false')!='false'
Regards,
Yvonne
Hi Yvonne,
your sample don't work on web preview.
1701
barrymavin
2018-06-12, 09:09
Can I use:
Lianja.evaluate("mylib::mylibproc('{}')") ?
Fabio,
Tell me what you think {} is substituted for. Then maybe you can answer your own question.
barrymavin
2018-06-12, 09:15
Ok Fabio.
you need to double the single quotes around the {} as keylookup() is a built-in function that will proxy a call to keylookup on the server.
You are not enclosing {} in quotes to the server.
‘\’{}’\’
That should properly enclose the value substituted for {} and it will be sent as ‘WILMK’
Fabio,
Tell me what you think {} is substituted for. Then maybe you can answer your own question.
Hi Barry,
this is to use a custom validate code.
for example:
you're insert a sales order for cusromer "WILMK"; this code it's right.. but the customer are suspended cause have a not payed invoice..
yvonne.milne
2018-06-12, 09:22
Hi Yvonne,
your sample don't work on web preview.
Hi Fabio,
Yes, it does. Put it in the field's validation attribute as you said you were doing in your test App.
Regards,
Yvonne
i've updated the Validate:
Lianja.evaluate("mylib::mylibproc('\'{}'\')")
but I got the error:
mar giu 12 16:24:40 2018
**** Lianja error ****
mylibproc('\'WILML'\')
^
')' was expected
mar giu 12 16:24:40 2018
**** Lianja error ****
Lianja.evaluate("mylib::mylibproc('\'WILML'\')")
^
METHOD 'EVALUATE' not found
Hi Fabio,
Yes, it does. Put it in the field's validation attribute as you said you were doing in your test App.
Regards,
Yvonne
but I want to insert the validate on the section formitem... not in the table column...
barrymavin
2018-06-12, 09:31
Hi Barry,
this is to use a custom validate code.
for example:
you're insert a sales order for cusromer "WILMK"; this code it's right.. but the customer are suspended cause have a not payed invoice..
Yes I have a good idea what validation is used for. :)
What I was trying to explain to you is that Lianja.evaluate() has no clue what {} is.
When you specify {} in the validation expression for a formitem, the framework knows what formitem is associated with {} and it can then substitute the current input text value.
{} is primarily used to substitute the current value associated with a UI element. In certain cases e,g Data Mapping on the server it is used to substitute current table.column value.
yvonne.milne
2018-06-12, 09:34
Yes, that's what I meant. Put it in the validation attribute for the field in the Form Section.
barrymavin
2018-06-12, 09:34
You are getting yourself really confused. You asked about how to do this using keylookup() which my response was replying to then you did it using Lianja.evaluate()... different code.
barrymavin
2018-06-12, 09:35
i've updated the Validate:
Lianja.evaluate("mylib::mylibproc('\'{}'\')")
but I got the error:
mar giu 12 16:24:40 2018
**** Lianja error ****
mylibproc('\'WILML'\')
^
')' was expected
mar giu 12 16:24:40 2018
**** Lianja error ****
Lianja.evaluate("mylib::mylibproc('\'WILML'\')")
^
METHOD 'EVALUATE' not found
Why are you escaping this with Lianja.evaluate()? Nobody told you to do that.
barrymavin
2018-06-12, 09:37
Why are you escaping this with Lianja.evaluate()? Nobody told you to do that.
Apart from that the last quote is mistyped. :(
Yes Barry, true...
but the subject is: DataValidation.. :-)
in the first, I've try with rlookup, keylookup.. sqllookup..
then, I've thinked about a more complex test.. and now the reale focus is on the
Lianja.evaluate("mylib::mylibproc('\'{}'\')")
if is possible.. good.
else.. I need to found other way.. or back to desktop App.. :-(
barrymavin
2018-06-12, 09:46
Try reading the replies and following what is said.
Don’t imply validation doesn’t work in web apps. That’s just not the case. You are struggling to get the javascript syntax right with substitution of values that get executed in the server.
Furthermore you asked on tickets, were replied to then proceeded to have real time response on the forums at 9:30pm my local time.
As usual I will put a small example together for you that you can copy and study. Tomorrow.
My goal is:
use a Web App as a front end, with a minumum JavaScript code and delegate to a server Lianja/VFP procedure all the code..
If possible.. :-)
thanks
Fabio
Hi Phabio,
To minimize your confusion, you (and anyone else making calls to backend VFP prgs) ought to be using exports.conf, rather than evaluate(...) which requires double sets of quotes etc.
This is what a calls to the backend look like when using exports.conf:
var loInfo = process_query_string(lcquery_string);
where process_query_string.prg resides on the LCS.
Why would anyone want to use Lianja.evaluate when it can be so much easier?
The exports.conf entry for this is also easy:
process_query_string
exports.conf file itself can be in the app directory, the library directory, or both.
Hank
Hi Hank,
thanks.. I try.
Fabio
But I can't insert directly the function into a click delegate.. I need to create a javascript code to call the VFP function..
I've try but not work for me..
I've created a button:
////////////////////////////////////////////////////////////////
// Event delegate for 'click' event
function page1_section2_field1_click()
{
// insert your code here
var loInfo = myProc("Test");
};
on exports.conf
myLib,myProc,VFP
then, myLib.prg
procedure myProc(m_value)
lianja.showMessage("MyProc")
endproc
but I get:
mar giu 12 18:04:25 2018
**** Lianja JavaScript error ****
Traceback (most recent call last):
page1_section2_field1_click() at 15
<global>() at 1
ReferenceError: Can't find variable: myProc
Ok, work.. but only on Web App View.. not in App Builder.
a little hard to debug the server side procedure.
Now I wait the sample from Barry.
thanks Hank
Hi Phabio,
I set up a test harness each of my server side procedures. If it works there, then the only issues can be the parameters fed to the procedure. Those I can debug in the .js file by using the debugger (see my reply to James Patterson on that issue). Just a prg that feeds the parameter(s) that the server side procedure sends.
I can then, in the .js file in the debugger, examine what is coming back. I most often return the data to a var before using it, as that allows me to examine the return values.
Hank
barrymavin
2018-06-12, 18:55
This thread is jumping all over the map.
Developing Web Apps as you should know is stateless. The client and the server state are not consistent as they are while building a desktop app.
You need to develop your app with that in mind.
Lianja handles a lot of the client server interaction for you but you nevertheless have to design how your app works properly.
In this particular case you are wanting to perform a cross table lookup from the UI NOT validation in the database engine.
I will provide an example lpk for you BUT you need to understand that validating the existence of keys from the UI is not going to stop you inserting duplicate records.
Why you may ask?
If this is done in the database engine the record is locked during the insert operation so the non existence of a key can be guaranteed at the time of insert.
If it is checked in the client UI no such locking occurs. Therefore from the time of the keylookup being evaluated to the time of the record being inserted another user could have inserted a record with the key.
I have on several occasions pointed this out.
For real time transaction systems you still need the validation in the database engine too.
Hi Phabio,
I set up a test harness each of my server side procedures. If it works there, then the only issues can be the parameters fed to the procedure. Those I can debug in the .js file by using the debugger (see my reply to James Patterson on that issue). Just a prg that feeds the parameter(s) that the server side procedure sends..
Hank
barrymavin
2018-06-12, 22:46
This is all working as per the attached screenshot in 4.2 Beta19.
The issue was related to you using keyLookup() to check for the existence of something in the validation. The problem was that the server knows nothing about the database for the table you specified. I have handled this now and it is working across all clients. So for your use case this is now working. See the validation i specified in the image.
1703
This thread is jumping all over the map.
Developing Web Apps as you should know is stateless. The client and the server state are not consistent as they are while building a desktop app.
You need to develop your app with that in mind.
Lianja handles a lot of the client server interaction for you but you nevertheless have to design how your app works properly.
In this particular case you are wanting to perform a cross table lookup from the UI NOT validation in the database engine.
I will provide an example lpk for you BUT you need to understand that validating the existence of keys from the UI is not going to stop you inserting duplicate records.
Why you may ask?
If this is done in the database engine the record is locked during the insert operation so the non existence of a key can be guaranteed at the time of insert.
If it is checked in the client UI no such locking occurs. Therefore from the time of the keylookup being evaluated to the time of the record being inserted another user could have inserted a record with the key.
I have on several occasions pointed this out.
For real time transaction systems you still need the validation in the database engine too.
Hi Barry,
you're right..
but I need to give feedback to the user also during the data input.. not only whenn the user save the records..
This is all working as per the attached screenshot in 4.2 Beta19.
The issue was related to you using keyLookup() to check for the existence of something in the validation. The problem was that the server knows nothing about the database for the table you specified. I have handled this now and it is working across all clients. So for your use case this is now working. See the validation i specified in the image.
1703
Thanks
I try and I do some experiments.
Fabio
qaslyday
2018-11-23, 06:51
hello all users. i am quas wenkis from mali.