Google script openById not working?

this is the code i wrote:

function importEventData(){ var dFile = DocsList.getFileById("0Ar2YhVnsK7LLdGVrUFdpRUVQTHJ0aG1SVkp6V0JMMkE"); var text = DocumentApp.openById("0Ar2YhVnsK7LLdGVrUFdpRUVQTHJ0aG1SVkp6V0JMMkE").editAsText().getText(); return text; }; 

The first line of the function works. But, unfortunately, in the second line, the Google compiler stops and says: β€œThe document is missing (it may have been deleted.)” Now I try for several hours, searching the network, but I can’t find the problem. The script has permissions to my gDrive. Although I tried to get the identifier from the dFile.getId () function. But this creates the same line and the same error.

+4
source share
1 answer
 var text = DocumentApp.openById("0Ar2YhVnsK7LLdGVrUFdpRUVQTHJ0aG1SVkp6V0JMMkE").getBody().editAsText().getText(); 

You need to add .getBody() to .editAsText() , because DocumentApp.openByID('id') returns a document class object, and the editastext method applies only to the body object. This can be seen from the Google documentation: https://developers.google.com/apps-script/reference/document/document-app

+1
source

Source: https://habr.com/ru/post/1443207/


All Articles