I am a beginner in java script, and I have got a problem here and would really appreciate the help.
I created a function called menu and I want to get a value from the user in an excel sheet and do an action based on that value in another function. So I have two questions:-
1- When i create 2 functions in java script and initialize a variable A in function 1, can I use this variable in function2? I couldn’t test that because I’m using google app script and I can only run one function.
2- (In the code) –> How to get the value from the use and use it in another function (If my first question is true). The value I’m trying to get is the wn, and i tried to Logger.log(wn) twice and they had the same values(348-372)!
function menu(){
//get the good week number
var date = new Date();
var wn = [(Math.floor(WEEKNUMBER(date))+3).toFixed(0)]
do {
wn.push((wn[wn.length-1]-1).toFixed(0))
} while(wn[wn.length-1] != 348);
var line = "<select style='width:60px;height:40px;' id='select'>"
for ( var x in wn ) // thats the loop taht is going to show all the weeks for the user
line +="<option>" + wn[x] + "</option>"
line +="</select>"
Logger.log(wn);
var ui = SpreadsheetApp.getUi();
var html = HtmlService.createHtmlOutputFromFile('Selector')
.setWidth(200)
.setHeight(150).setContent("<div>"+line + "</div><br>. <div><button onclick='reset()'>Confirm</button> </div>. <script>function reset(){var wn = document.getElementById('select').value;document.getElementsByTagName('Body')[0].style.cursor = 'wait';google.script.run.withSuccessHandler(function (){google.script.host.close();}).readWP2(wn);}</script>")
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.showModalDialog(html, 'Please select a week number');
Logger.log(wn);
}
If you need more explanation please let me know