Using fetch() in function results in "output not defined"
<p>I have been using Zapier for several weeks now and as per normal, our needs and wants have become more complex as we build each feature. Hence my current issue with some JavaScript in a "Code by Zapier". </p>

<p>Note for any answer: Myself and the team of programmers I have available are not JavaScript experts but we do understand most concepts.</p>

<p>Aim: To make a fetch() call only if an input to the javascript is true.</p>

<p>Problem: Zapier always returns "output not defined" when the fetch() is included in the code.</p>

<blockquote>
  <p>ReferenceError: output is not defined theFunction</p>
</blockquote>

<p>ie: The overall code structure is ok, the way I am using fetch() and returning and processing is not. </p>

<p>I have tried a gazillion variations and utilised some great posts here, but nothing solved the issue.</p>

<p>The simplified code looks like this:</p>

<pre><code> //This does the Fetch:
function doFetch(urlAddress) {
    console.log("2. Doing Fetch");
    return fetch(urlAddress)
        .then(function(res) {
            return res.text();
        })
        .then(function(response) {
            //Hardcode a return.
            console.log("3. Returning Response");
            return response.json();
        });
}

if (input.emailHasChanged == "true") 
{
    //Do Something
    console.log("1. Updating Email");
    doFetch(urlAddress)
        .then(function(response) {
            //Do something with Reponse.
            console.log("4. Doing Something: ", response);
            callback(null, response);
        });
}
else
{
    //Do Nothing
    console.log("1. Not Updating email");
    output = {id: 2};
}
</code></pre>

<p>I believe it is the way I am either returning from the fetch() or the asynchronous nature of JavaScript. </p>

<p>Note: Zapier predefines the 'input' and 'output' variables for me. 'output' is initially Null and a value must be set by the code.</p>