0

i have two functions in google apps script

code.gs:

function getdata1(e) {
// works..
return array_1;
}

function getdata2(e) {
// works..
return array_2;
}

index.html:

function getData1(e) {
  google.script.run.withSuccessHandler(dispData1).getData1(e);    
}
function dispData1(array_1) {
// here i can acces the value of array_1.
// NOW i need to access the values of array_2 from the other function (getData2)
}

thanks for any help

2 Answers 2

1

To run both functions simultaneously, use promise.all:

const gsr = func =>
  new Promise(res => google.script.run.withSuccessHandler(res)[func]());

Promise.all(['getdata1', 'getdata2'].map(f => gsr(f))).then(
  ([arr1, arr2]) => {
    console.log({ arr1, arr2 });
  }
);
Sign up to request clarification or add additional context in comments.

Comments

0

Add an intermediate function called getAllData()

//.gs file
function getAllData(){
  var arr1 = getdata1();
  var arr2 = getdata2();
  return {
    array_1: arr1,
    array_2: arr2
  }
}

And then call getAllData from your html

//.html file
function getAllData(e) {
  google.script.run.withSuccessHandler(dispData).getAllData(e);    
}

function dispData(response) {
 var array_1 = response.array_1
 var array_2 = response.array_2
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.