Client Events using JavaScript

Hi All,

Today I want to share with you one way how you can add some client validations/calculation using JavaScript right in the browser with no accessing server data.

javascrypt acumatica

In general i would suggest you to not do any complex calculations on client side and always use server for all data manipulations. However in some specific situations this approach may save a lot of processing time because client events may do calculations right in the browser.
Also note that client logic will be available only for browser users and will not be triggered from web services API and Mobile application.

The scenario that i want to do is quite simple – trigger the code after the value changes in some controls and validate/calculate its value. This example is designed for demonstrating purpose only so I would like just to show a notification box with new value when someone change GL Batch description.
As a much better example of client events may be a playing of sound on button/control click. Really good explanation and example example is provided on Stack Overflow.

To add required validation lets complete following steps:

  1. Create a new customization project
  2. Open required screen in the customization browser
  3. Locate control that requires additional validation
  4. Add a JavaScript control near to the required
    Add a JavaScript control acumatica
  5. For the JavaScript element we need to specify new JavaScript code that will contains validation function. Our function will be called on description control value change.
    contain validation function javascrypt acumatica
    • function myValueChanged(control, eventArgs) { alert(eventArgs.Value); }
  6. Now we need to register the new client event for the description control. Client events are hidden property so to see it you need to remove filter on top of the grid. Inside client events collection you can find most common user interaction events that can help you to catch different user’s actions. I will use ValueChanged event.
    ValueChanged event acumatica
  7. Now you can publish customization.
As soon as customization will be published you can test the results.
ValueChanged event acumatica

Lest check the function that we have added to the script control:

function myValueChanged(control, eventArgs) 

This function actually is a standard event handler that has 2 parameters: control that has rises event and event arguments. You can use all parameters for calculations. In my case event arguments will contains new value changed by user.

Also you may want to debug your java script code. This will be quite simple using Google Chrome debugging tools. Just click F12 to show panel and refresh you page to load all possible scripts.
Your custom function will be included into the page html code (Use search to find your function).
Just put a break-point there and browser automatically notify you when function is triggered.
You can use all possible tools to understand what is going on and what parameters you can use.

 debug java script code acumatica

Have a nice development!

5 Replies to “Client Events using JavaScript”

    1. Any way to set current in javascript api? Or maybe do a redirect to screen? We are having some strange issues with a current not being correct on a grid and looking to work around that.

      1. The only way I can recommend is to use redirect with keys in the URL – …../Main?ScreenId=SO301000&OrderType=SO&OrderNbr=001252
        There is no way to set current from JS, as the current is saved on the server session.

Leave a Reply

Your email address will not be published. Required fields are marked *