-
Tidying up data
Hi guys
We have a js function which tidies up user data entry PROPER(), UPPER() etc. at the end of an edit. It is called from one section but updates the data is all sections after edit on a single table.
In DEV that works well when we call it from the AfterEdit delegate but does not seem to do the same in web. We have tried other delegates but cannot seem to update the fields in web.
Which delegate would be best to call this in web?
Looking at just one field, we call :
var lname = proper(Lianja.getElementByID("pcust.scust.txtname" ).value);
Lianja.getElementByID("pcust.scust.txtname").text = lname;
if ( Lianja.isDevMode() )
{
Lianja.getCursor("cust").setData("name", lname);
}
Thanks in advance
Simon
-
Hi Simon
The "afteredit" delegate is the wrong place to do this as this is called when you exit "editmode"/ This elegate is typically used to re-show UI elements that were hidden in the "before edit" delegate.
When "afteredit" is called data has already been updated or inserted.
You need to use the "beforeupdate" delegate to change the cursor data before performing an update or alternatively the "beforecreate" delegate to change the cursor data before performing an insert.
It is more normal practise to use input masks for the purpose you mention.
-
Hi Barry
Thanks for info.
Agreed, input masks would be preferred but don't think there is a proper() input mask.
In DEV Got the BeforeUpdate() delegate working and is just what we needed.
However FYI from the GUI, BeforeUpdate() is NOT called from the save button, but only by repressing the edit button.
This behaviour is consistent.
Should the save button call BeforeUpdate() too?
However in web the data does not get updated. Any thoughts?
Obviously in web the GUI buttons are slightly different. Could it be linked to the save button issue?
Thanks
Simon
-
Hi Simon,
"However FYI from the GUI, BeforeUpdate() is NOT called from the save button, but only by repressing the edit button."
What GUI are you referring to? The web client or the App Builder?
As i mentioned to you in a previous post, in 7.2 the delegates MUST return true to be applied otherwise they will ignore the action. This is to provide hooks into the process of Create,Update and Delete.
So make sure you return true from your beforupdate delegate.
These delegates are all working as expected in desktop apps and web apps.
I have added beforeupdate and afterupdate to the example_webapp1 sample app which you can run and study.
-
Hi Barry
This seems to be 2 issues.
1) "However FYI from the GUI, BeforeUpdate() is NOT called from the save button, but only by repressing the edit button." refers to the App Builder GUI.
Lianja.writeOutput() step markers show the BeforeUpdate() only runs when the edit button is pressed to end the edit and does not run when the save button is pressed - again both in the App Builder.
2) The same step markers show that in web, the BeforeUpdate() does run when save is pressed and the changes have been made to the field values inside BeforeUpdate().
ie name = smith
Proper(name)
at the end of BeforeUpdate(), both
Lianja.getElementByID("pcust.scust.txtname").value ) = Smith
Lianja.getElementByID("pcust.scust.txtname").text = Smith
and BeforeUpdate() returns true
but the text does not change in the browser.
Any thoughts?
Cheers
Simon
-
Hi Simon
Did you mean to write:
Lianja.getElementByID("pcust.scust.txtname").value = “Smith”
Try opening the example_webapp1 app and run it. You will see the before update and after update delegates called when editing.
I will look into this with canvas sections to confirm.
Lianja.getElementByID("pcust.scust.txtname").text = “Smith”
Are you referring to a canvas section?
-
Hi Barry
Form section.
Sorry - not being exact.
Edit, Data changed and "smith" in field when save is pressed in web.
Beforeupdate() fires and changes value/text in field to "Smith"
Code is
var lname = proper(Lianja.getElementByID("pcust.scust.txtname" ).value);
Lianja.getElementByID("pcust.scust.txtname").text = lname;
At the end of the function, if we retest the values, both ....txtname.value and ...txtname.text are equal to "Smith"
And Beforeupdate() returns true.
So Beforeupdate() is working and returning true but something later in the sequence is either reverting the changes or simply not accepting them in the edit.
Hope that helps
Cheers
Simon
-
Hi Simon
All you are doing there is updating the UI. Programatic updates like that do not affect the active cursor that the UI control is bound to so when the update is sent to the server it sends the changed active cursor values.
You therefore need to update the active cursor rather than the UI in the beforeuodate delegate
Lianja.getCursor(“tablename”).setData(“columnname” , lname);
That is the equivalent of what you would do in VFP code in a desktop app
replace tablename.columnname with lname
-
Hi Barry,
So when one wants to make changes does one update the cursor then refresh the control in the UI, or change the values in the UI and save?
David
-
Hi David,
When you click "save" while editing, the beforeupdate delegate is called "before" the update is sent to the server and the afterupdate delegate is called after the update successfully completes.
After the update completes (and no server side validation fails) the data is re-read from the server (it's multi-user remember so others may have changed some columns that you did not) and refreshed into the UI.
So when using beforeupdate to alter data that you wish to be included in the update you only need to update the cursor data as i described previously.
In your case building desktop apps just use a LianjaScript/VFP REPLACE statement in the delegate as i described above.