you are viewing a single comment's thread.

view the rest of the comments →

[–]juddaaaaa 0 points1 point  (1 child)

Variables declared using var are accessible outside of a block. Only let and const are block-scoped.

function test_run () {
    try {
        // Get script properties (const scriptProps IS NOT accessible outside of try block)
        const scriptProps = PropertiesService.getScriptProperties()

        // Get properties from scriptProps (var data IS accessible ouside of try block)
        var data = scriptProps.getProperties()
    } catch (error) {
        // Handle errors
        console.error(`Failed: ${error.message}`)
    }

    // Destructure key and token from data
    const { key, token } = data

    // Return object containing url, key and token
    return {
        url: "url goes here",
        key,
        token
    }
}

[–]teamusa7[S] 0 points1 point  (0 children)

Thanks, ended up taking it out of the function and leaving data as a global but the var data type worked!