Problem with AJAX not calling Javascript Methods

Hi
I have another strange one since I upgraded to the latest SC version.
Scenario 9.10.021 (2)

  • I have a FORM, where there is a dropdown list.
  • The chosen value is colour coded based on a lookup to a global array.
  • The colouring uses a javascript method that works fine on the onload event
  • I need to recolour the value if it changes (To relate to the new selected value’s colour

I have an AJAX onChange event setup that is properly triggered and I can see it works because for testing purposes I change a field to show the correct colour value in hex… so far so good.
I then call a Javascript method…
sc_ajax_javascript(‘test’); // calling javascript

this is a simple method that only shows an alert (and it works fine if I trigger it using the main Javascript events)

Unfortunately nothing happens… it looks like the method is not called.

As part of testing, I then tried to print a message using the sc_ajax_message macro (Using the simple example in the manual.

/**

  • Display a message after an AJAX call
    */

// Javascript message parameters
$javascript_title = ‘My Message’; // Javascript message title
$javascript_message = ‘This is a test message.’; // Javascript message contents

// Display javascript message
sc_ajax_message($javascript_message, $javascript_title);

Again nothing happens…

I’ve checked the simple stuff like scope of the macros (Which looks OK) and there are no console errors.

Any suggestions about what the problem might be?

Dear @ibatey,

Firstly, we apologize for the delay in responding.

We carried out tests on the Form’s Ajax events (onChange, onFocus, onClick, onBlur), both by calling a JS method with the sc_ajax_javascript macro, and also using the sc_ajax_message macro, following the examples you sent us above.

Both in a new application created from scratch in version 9.10.023, as well as in applications that already existed and were created in versions well before 9.10.023, the event was triggered correctly, as defined.

In a new application created from scratch in version 9.10.023, do you continue to have problems using the event with the aforementioned macros? Or does the problem only continue to occur with existing applications?

Let us know other details besides those already mentioned above so that we can help you.

Best regards!

The application at fault is an old one that was migrated. It did NOT previously have any AJAX methods. I wanted to embellish it with the colour coding so added the relevant AJAX event and the code.

It behaves as though there is a javascript error (i.e does nothing), but there are no console errors to indicate any problem. When this didn’t work, I simplified the Javascript calls (to simply display an alert) so that I knew the fault was not in my code.

I can call the methods OK from the main Javascript functionality (i.e. using the Javascript sub menu in the application), just not from the AJAX.

I also know that the AJAX event is triggering as I test it by updating a field using PHP.

While its a problem, it is not on every app and other applications work fine. It could be peculiar to the specific application. I haven’t tried to recreate it yet, as I’m focussed on other things right now.

@Danilo_Lima I’ve spent some time on this today. I recreated the grid from scratch and added the relevant AJAX and Javascript as my first activity after creating the app.
Everything worked fine!

I then gradually added more of the other code step by step, testing as I went. I found that the onScriptinit event was causing the problem. By systematically switching each piece of code on and off (using /*), I was eventually able to isolate it to the use of the sc_field_display macro.
It seems that if you use the macro for a field that you are not displaying on the form (I was originally, but obviously removed it later), then it does not give an error, BUT… screws up the Javascript calls after it fails. I also tested it by using it on a non-existent field and got the same result… no error, but a javascript kill.

  • As a workaround, if you find this circumstance, then check every use of this macro is correct.
  • It would be good if NM could update the macro to avoid such an obscure failure (Check field exists on grid perhaps!)

NOTES: I didn’t check whether the Javascript kill is permanent for all AJAX events after the error, or whether it is isolated to the particular running app.

1 Like

Thanks for your feedback, and how wonderful that you managed to overcome the situation so that the resource works again.

When you say “use the sc_field_display macro for a field that is not displaying on the form”, what exactly do you mean? That you started with the field turned off in onScriptInit and then used the macro again to enable (on) the field? Or that the field is not selected for the form under “Field positioning” or “Edit fields”?

Best regards!

The latter. I had a field displayed in a normal block, which I was manipulating with the macro. At some point, I decided I didn’t need the field and moved it out of the block in field positioning/Edit Fields. The macro still appeared to work but was hiding the AJAX problem as i didn’t use AJAX till recently.