FreshService - ShowModal Promise Issue

Hey all,

I seem to be having issues when I’m calling ‘showModal’,

I’m calling the following from a button press on an asset panel. The modal shows up perfectly fine, however due to their being a promise issue, the code continues on.

I’m just wondering the best way to approach this? If I remove the showModal portion the code works fine, without any promise issues. However as soon as I add it back in I get the promise issue - even with a blank .html.

Any pointers would be great!! I’ve tried my hardest to avoid posting - but I’m all out of ideas :(.

async function removeDeviceConfirmed(){
    let curAsset = await getCurrentAsset();
    let curUser = await getCurrentUser();

        let confirmation = client.interface.trigger('showModal', {
            title: 'Are you sure?',
            template: './views/delete-confirm.html',
            data: {
                username: curUser,
                asset: curAsset
            } });
}

Hi Jason,

Try one of these two approaches:

  1. Await the Promise: Since showModal returns a promise, you should await it to ensure the modal has been shown before executing any subsequent code.
  2. Handle Promise Resolution and Rejection: Implement .then() and .catch() to handle the resolved value or potential errors respectively.

In my experience, using then and catch has generally solved this type of problem and, if nothing else, you will have a clearer error message.

try {
  let data = client.interface.trigger('showModal', {
  title: 'Sample App Form',
  template: './views/modal.html' });
  console.log(data); // success message
} catch (error) {
    // failure operation
  console.error(error);
}

I hope this helps you!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.