UI Builder - Refresh Data Resource

CarlJSchmidt
Tera Expert

Hi experts,

 

in the UI builder, I trigger a flow and want to show a loading screen to the user while the flow is still running.

To this end, I've added a button to trigger the flow. The following client script is executed when the button is clicked:

 

function handler({api, event, helpers, imports}) {
    // Show the loading screen.
    api.setState('showLoadingScreen', true);
    
    // Trigger the flow by updating the record.
    api.data.update_record_1.execute({
        table: "my_table",
        recordId: api.data.record.sysId,
        // Flow is triggered for all records for which `flow_status` equals "started".
        templateFields: "flow_status=started",
        useSetDisplayValue: false
    })

    // The last step of the flow set `flow_status` to "completed". 
    // Repeatedly (every 500ms) check if this condition is met.
    var intervalId;
    intervalId = helpers.timing.setInterval(() => {
        // Get the latest value of `flow_status` for the current record.
        api.data.look_up_record_1.refresh();    /* <-- DOES NOT WORK. `flow_status` remains as "started". */
        if (api.data.look_up_record_1.result.flow_status == "completed") {
            // Hide the loading screen and stop the repeated check.
            api.setState('showLoadingScreen', false);
            helpers.timing.clearInterval(intervalId);
        }
    }, 500); 
}     

 

For me, the code above results in an infinite loop, because even after executing api.data.look_up_record_1.refresh(); the value obtained from api.data.look_up_record_1.result.flow_status still reads as "started".

 

If I check the record in my_table directly, I can see, that the value for flow_status has been updated by the flow to "completed". However, somehow this information is not picked up by the data resource look_up_record_1 in the UI Builder.

 

Is there a way to make the latest value of flow_status known to the UI Builder are to somehow prevent the user from interacting with the UI while the flow is running? Runnig the flow in foreground unfortunately only prevents interaction on the affacted part of the UI. 

 

Thank you in advance!

 

1 REPLY 1

TemporaryUserNO
Tera Contributor

Hey,

 

Is the data broker you're triggering a server mutating transform data broker? If so then you probably can't use the refresh function on it, and rather need to trigger it again with execute function. It might also not be a bad idea to try it out either way, as perhaps the results are cached from the previous run or something. 

 

Hope it's helpful 🙂