Filippo
Filippo

Reputation: 320

Call a web-app script within a script with UrlFetchApp.fetch

I have a script deployed as a webapp. It is asking too many permissions to the user, so I want to divide the script in two parts. One will be run as the user so that I can get his/her email, the other one will be run as me to edit a spreadsheet.

I have tried to use the UrlFetchApp.fetch. I do not get an error, but the second script does not write in a cell as it is supposed to do. I am not sure what is wrong.

Webapp1 - accessed by user (showing only one relevant function. There is more not relevant code which I excluded to show a simple example):

EDITED CODE:

function ServerSideFunc() {
  var ss = SpreadsheetApp.openById('1kLZ3CHPkODHRc_judkUSJ3ocWVPh6nIIjJS7TLLejIg');
  var sh = ss.getSheetByName('Database');

  var response =UrlFetchApp.fetch("https://script....../macros/s/.....s/exec");

}

Webapp2: (the one published in the URL above and run as me)

function test() {
  
  var i = 408 //I would like to pass this as parameter eventually from webapp1
  var ss = SpreadsheetApp.openById('1kLZ3CHPkODHRc_judkUSJ3ocWVPh6nIIjJS7TLLejIg');
  var sh = ss.getSheetByName('Database');
  var str = "OK";
  sh.getRange(i+1, 2).setValue(str);
   
}

function doGet() {
  
  var output = HtmlService.createHtmlOutputFromFile('list');
  return output;
  
}

Few more notes:

Upvotes: 1

Views: 1129

Answers (1)

TheMaster
TheMaster

Reputation: 50761

The if condition:

if(vA[i][3]+" REQ ID: "+vA[i][0] == value) {

will never be true as anything + "REQ ID: " will never be equal to "TEST"(value). Thus the urlfetch is never executed.

Upvotes: 0

Related Questions