What I am trying to do:
1- When someone clicks on the button (class = btn), it retrieves values of the options selected in an array. See the HTML Code.
2- I stored the array into an object - facebookAccountData
3- Pass the data into Code.gs function makeRequest by running google.script.run command.
When I try to run makeRequest direct from the script editor, I get a ReferenceError. I am not able to do console.log in makeRequest function.
HTML
<div class="form-group">
<label for="fieldsData">Select Fields:</label>
<select id="fieldsData">
<? var data = ACCOUNTDATA.adAccountUIFields ?>
<? if (data.length > 0) { ?>
<? for (i=0; i<data.length; i++) { ?>
<option value="<?= data[i] ?>"><?= data[i] ?></option>
<? } ?>
<? } ?>
</select>
</div>
<div class="form-group">
<button id="btn">Run it</button>
</div>
</div>
Javascript HTML
<script>
document.getElementById("btn").addEventListener("click",retrieveFacebookData);
function retrieveFacebookData () {
var facebookAccountData = {};
facebookAccountData.facebookFields = $('#fieldsData').val(); // [cpc,impressions,spend]
google.script.run.makeRequest(facebookAccountData);
}
</script>
Code.gs
var ACCOUNTDATA = {
adAccountUIFields : ['cpc','impressions','spend']}
function makeRequest(facebookAccountData) {
facebookAccountData = {facebookFields: [cpc,impressions,spend]};
console.log(facebookAccountData.facebookFields);
}