Module cancelClicked event running through before API calls completed.

Hi there,

I'm refactoring a custom 'Multiple Attachments' field type.

The user uploads files, via AJAX request to an API endpoint, while record is in 'edit' action.

On 'cancel' ('cancelClicked' in 'record.js'), I need to remove those uploaded files again, but the 'cancel' event is running through before I get a chance to delete them all (also via AJAX request to API endpoint).

Specifying synchronous AJAX requests doesn't help.

It works fine when deleting files that have already been uploaded on 'Save', since I can tie into the 'before_save' logic hook, but there isn't an equivalent mechanism for 'cancel'.

I'm still a bit new to SugarCRM, so may be missing something glaringly obvious.

You help will be greatly appreciated.

Cheers,

Daniel.

  • So, I solved this, and while I feel a bit stupid, I'd better post the solution.

    I'd made an incorrect assumption about the problem.

    My script was running fine, but I'd made an error in how I was iterating over the array of files.

    I was using a 'for...in', but was doing a splice within the loop (to remove files that didn't require deleting), which was throwing out the index of the array. This meant I was only processing about half of the array elements.

    I swapped the 'for..in' for a 'while (array_length--)' loop, and it processed all elements as intended.

    Woo!