Hopefully, this might help someone else avoid wasting countless hours as I have this week trying to get Javascript code to execute automatically after an Ajax callback.
With a grid displayed on the screen, I used an Action Button to trigger an Ajax Callback. The Xbasic function manipulated records in the underlying table and I needed to automatically refresh the grid upon exit from the Xbasic function. After watching every related video and searching the Wiki and message board multiple times, I still could not get the Javascript to execute automatically upon exiting the function. The command to do so is rather simple
FunctionName = "{grid.Object}.refresh();"
and should refresh the grid upon exit from the function, but it simply did not work for me. There was no error message or indication that I had done something wrong. I then used a workaround by following the Ajax Callback with Inline Javascript using the setTime method to create a delay before issuing the refresh grid comand, which worked, but with a fixed time delay that I had to make long enough to support processing the maximum number of records expected in the table - definitely not optimal!
Refusing to give up, I was reviewing one of Peter Gruelich's helpful posts for about the thirteenth time when I for the first time paid attention to his function declaration, which was "function SomeFunction as c (e as p)". The "c" jumped off the page at me. Looking at my own function declaration, I found that it was "function ProcessInv as v (e as p)" - I had copied another function and changed only the name and code, not the data type! After correcting the data type to "c", the function worked flawlessly and refreshed my grid upon exit.
It is amazing how one can be blind to something that is, in retrospect, so obvious. The Javascript code that is returned from the Ajax Callback is contained within a string, therefore the function must be declared as character data type for the Javascript to be returned and executed.
Terry
With a grid displayed on the screen, I used an Action Button to trigger an Ajax Callback. The Xbasic function manipulated records in the underlying table and I needed to automatically refresh the grid upon exit from the Xbasic function. After watching every related video and searching the Wiki and message board multiple times, I still could not get the Javascript to execute automatically upon exiting the function. The command to do so is rather simple
FunctionName = "{grid.Object}.refresh();"
and should refresh the grid upon exit from the function, but it simply did not work for me. There was no error message or indication that I had done something wrong. I then used a workaround by following the Ajax Callback with Inline Javascript using the setTime method to create a delay before issuing the refresh grid comand, which worked, but with a fixed time delay that I had to make long enough to support processing the maximum number of records expected in the table - definitely not optimal!
Refusing to give up, I was reviewing one of Peter Gruelich's helpful posts for about the thirteenth time when I for the first time paid attention to his function declaration, which was "function SomeFunction as c (e as p)". The "c" jumped off the page at me. Looking at my own function declaration, I found that it was "function ProcessInv as v (e as p)" - I had copied another function and changed only the name and code, not the data type! After correcting the data type to "c", the function worked flawlessly and refreshed my grid upon exit.
It is amazing how one can be blind to something that is, in retrospect, so obvious. The Javascript code that is returned from the Ajax Callback is contained within a string, therefore the function must be declared as character data type for the Javascript to be returned and executed.
Terry
Comment