How can a screen (block / page) refresh be actioned after a data update from an add on products (documint for example)

I need to refresh the screen (and data within) after an update to the data that has accurred by a third party add on. In this case I have a External URL button that triggers a Documint generation and saves it in an airtable field. The document is shows in the Modal Window that softR opens, but when that Modal Window closes the newly produced documint is not relfected in the item-details block. The process is therefore inititiaed from within softR but actually procecssed outside hence no refresh trigger.

Any ideas how I can achieve this.

TIA for reading…

I had a similar issue with an airtable automation which processes tasks updates in the background. I used a Custom Code block to reload the softr blocks on a timer. You’ll need to adapt this script based on your needs based. Sounds like you could use the “External URL button” to trigger a set of polling intervals for some amount of time afterwards.

<script>{

function dispatchReload() {
    // send a custom event to reload each block you need to update "reload-BLOCKID"
   	window.dispatchEvent(new CustomEvent('reload-status-list'));
	window.dispatchEvent(new CustomEvent('reload-task-list')); 
}

function setReloadTimer(ms, max) {
    let count = 0;
    
    let interval = setInterval(() => {
        count++;  
        // console.log({ ms, count, max });
        dispatchReload();
        if(max && count >= max) clearInterval(interval);
    }, ms);
}

// first argument is the polling interval (how many milliseconds)
// second argument is how may times to poll at that interval
setReloadTimer(1500, 2);
setReloadTimer(5000, 5);
setReloadTimer(30000); // this one auto reloads indefinitely every 30 seconds)

}</script>

Thanks for taking the time to reply.
I am not good at JS but I am sure I can work it out, but this bit I don’t understand is where I would put this code in order for the External URL Button to trigger it ?

<script>

function setReloadTimer(ms, max) {
    let count = 0;
    
    let interval = setInterval(() => {
        count++;  
        dispatchReload();
        if(max && count >= max) clearInterval(interval);
    }, ms);
}

function dispatchReload() {
    // send a custom event to reload each block you need to update "reload-BLOCKID"
   	window.dispatchEvent(new CustomEvent('reload-status-list'));
	window.dispatchEvent(new CustomEvent('reload-task-list')); 
}

window.addEventListener('call-api-success-BLOCKID', (e) => { // replace BLOCKID with your block name that has call api
     // for example, reload every 2 seconds 5 times
     setReloadTimer(2000, 5);
});

</script>

Thanks for this. I have tried it but not getting it to work. The button is an “Open URL” action so I wondered if this is triggering the ‘call-api-success-list-details1’ Below is what I have inserted and changed and feel this should work. Any help is so much appreciated. Code is not my strong point at the moment. (I have included the code prior to where I have inserted this which reloads other blocks and works well). It is in the PAGE header section. TIA

window.addEventListener(‘block-loaded-table2’, () => {
window.addEventListener(‘add-record-success-table2’, () => {
setTimeout(() => {
window.dispatchEvent(new CustomEvent(‘reload-block-list-details1’));
}, 1000); // 1000 milliseconds = 1 second
setTimeout(() => {
window.dispatchEvent(new CustomEvent(‘reload-block-table5’));
}, 1000); // 1000 milliseconds = 1 second
// setTimeout(() => {
// window.location.reload();
// }, 6000); // 1000 milliseconds = 1 second
});
});

function setReloadTimer(ms, max) {
let count = 0;

let interval = setInterval(() => {
    count++;  
    dispatchReload();
    if(max && count >= max) clearInterval(interval);
}, ms);

}

function dispatchReload() {
// send a custom event to reload each block you need to update “reload-BLOCKID”
window.dispatchEvent(new CustomEvent(‘reload-block-list-details1’));
// window.dispatchEvent(new CustomEvent(‘reload-task-list’));
}

window.addEventListener(‘call-api-success-list-details1’, (e) => { // replace BLOCKID with your block name that has call api
// for example, reload every 2 seconds 5 times
setReloadTimer(5000, 5);
});

Hey, you can check the code posted by Sveta as well.

1 Like

Thanks Aramo. I am using this code a lot and it works well. The issue I am haing is how to trigger this from an External URL action via a Item-detail block. Any help on how to get it working in that use scenario woud be helpful.

Ah, I see you just need a way to get a click event on the button. Is there more than one button in that block?

Yes, that is what I need to achieve. Yes, there are several buttons on the block. TIA