Help

Reset Input or re-run app

Topic Labels: Scripting extentions
Solved
Jump to Solution
2184 4
cancel
Showing results for 
Search instead for 
Did you mean: 
Tim_Lempicki
5 - Automation Enthusiast
5 - Automation Enthusiast

Is there a way to reset an input field? Say someone pulls up a record selection input and then they click off so nothing is selected the user is no longer able to go back and select something different.

As far as I know you can’t reset the input, remove the element and re-add it to let the user try again. I tried using a do while loop so that it could do the input instruction again if the variable is null.

If it isn’t possible to reset the input or remove the element and re-add another input, is there a way to re-run the script with a button or some other event?

1 Solution

Accepted Solutions
Tim_Lempicki
5 - Automation Enthusiast
5 - Automation Enthusiast

This is in a script block, yes.

I think I just needed some sleep after you told me it was possible and taking a look at it again this morning I figured out that I could just use recursion. If the user doesn’t select a record I have it call itself again. If a user selects a record I give them an option with a button to select a different record and have the function call itself again.

The one problem I was running into was that it just kept adding elements to the page. I found that while you don’t have DOM access in a script (as far as I know) you can use output.clear() to completely clear everything on the screen and have it rerun everything again.

async function main(){
    await getRecords();
    let record = await input.recordAsync("Pick a record", blankRecArr);
    if(record) {
        let createRecordBtn = await input.buttonsAsync(
            `You picked the '${record.name}' record.'`,
            [
                {label: "Create Online Program Record", value: 'create', variant: 'primary'},
                {label: "Pick another record", value: "cancel", variant: "danger"}
            ],
        );

        if(createRecordBtn === 'create'){
           //Do stuff
        } else if(createRecordBtn === 'cancel') {
            await reset();
        }
    } else {
        await reset();
    }
}

async function reset(){ 
    output.clear();
    await main();
}

await main();

See Solution in Thread

4 Replies 4

Hi Tim, and welcome to the community!

In a script block?

Yes, this is possible - the while loop needs a button that halts the execution and allows you to “continue” with a new set of elements.

Alternatively, you really need events that invoke the script block to magically update based on what users might select in terms of table records, etc. This is possible in a custom app - a script block based on the Airtable SDK.

Tim_Lempicki
5 - Automation Enthusiast
5 - Automation Enthusiast

This is in a script block, yes.

I think I just needed some sleep after you told me it was possible and taking a look at it again this morning I figured out that I could just use recursion. If the user doesn’t select a record I have it call itself again. If a user selects a record I give them an option with a button to select a different record and have the function call itself again.

The one problem I was running into was that it just kept adding elements to the page. I found that while you don’t have DOM access in a script (as far as I know) you can use output.clear() to completely clear everything on the screen and have it rerun everything again.

async function main(){
    await getRecords();
    let record = await input.recordAsync("Pick a record", blankRecArr);
    if(record) {
        let createRecordBtn = await input.buttonsAsync(
            `You picked the '${record.name}' record.'`,
            [
                {label: "Create Online Program Record", value: 'create', variant: 'primary'},
                {label: "Pick another record", value: "cancel", variant: "danger"}
            ],
        );

        if(createRecordBtn === 'create'){
           //Do stuff
        } else if(createRecordBtn === 'cancel') {
            await reset();
        }
    } else {
        await reset();
    }
}

async function reset(){ 
    output.clear();
    await main();
}

await main();

You can run a script from a button field. That will ensure that the first input record is set.

Scripting app has such limited capabilities that I find a lot of error checking to force the user to pick a record isn’t worth the coding effort. I just inform the user that the script is ending because no record was selected. If user didn’t pick a record by mistake, he can re-run the script and pick a record.

Yes - this is precisely the case; no DOM, but clear and re-render works but adds about 7 milliseconds to the process. :winking_face: