Status Update
Comments
ja...@google.com <ja...@google.com> #2
Hello, thanks for your report.
Unfortunately, I could not reproduce the issue. Inside the for
loop, does the line var body = targetDoc.getBody();
always return this error? Or does it fail after several loop runs? Can you reproduce this with another Script?
Thanks
ma...@gmail.com <ma...@gmail.com> #3
Hi, thank you for the answer. It always returns the error for me.
Attached is a quick video of what happens when I run the program.
Additionally, after checking my app script dashboard, and looking at failed executions, I came across one of these errors:
Exception: You do not have permission to call DocumentApp.create. Required permissions:
Yet, the scopes of the script already include that permission (screenshot attached)
I'm stumped. Is there anything else I should provide?
ja...@google.com <ja...@google.com> #4
Thanks for the quick reply.
Make sure you have reading or editing permissions, and check if the Document is in the Drive's Trash. If this is not the case, create a new Document and try with the new Id. Regarding the Scopes issue, go to
Cheers!
ma...@gmail.com <ma...@gmail.com> #5
The script creates a new document every time, so it just pops up in my drive. The document is never in the trash, until I delete it.
For the scopes issue, I tried removing the App's permission, and re-adding it by running the script again, but nothing changed.
I even copied every part of the script into a new document, and when running it again, the same exact error shows up...
Anything else I could try?
Thank you!!
ma...@gmail.com <ma...@gmail.com> #6
Actually, I think I just fixed the problem, but I have come across a strange issue.
Basically, I had a footnote in my google document. For some reason, having a footnote in the document causes that error to pop up.
After removing any footnotes (such as the screenshot shown below), everything is fine, and the document copies over.
Any idea as to why this may be happening?
Thanks!!
ja...@google.com <ja...@google.com> #7
Thanks for the information! I'm glad you found a workaround. I tried to reproduce the issue using a Document with footnotes but it worked as expected. Would you mind sharing an example of the Document, and a minimal reproducible example of the Script?
Thanks!
ma...@gmail.com <ma...@gmail.com> #8
This is the script I am using:
function speechDoc() {
var currentDoc = DocumentApp.getActiveDocument().getBody();
var targetDoc = DocumentApp.create('Speech Doc');
var totalElements = currentDoc.getNumChildren();
for( var index = 0; index < totalElements; ++index ) {
var body = targetDoc.getBody();
var element = currentDoc.getChild(index).copy();
var type = element.getType();
//Goes through each type of element
if( type == DocumentApp.ElementType.PARAGRAPH ){
body.appendParagraph(element);
}
else if( type == DocumentApp.ElementType.TABLE){
body.appendTable(element);
}
else if( type == DocumentApp.ElementType.LIST_ITEM){
body.appendListItem(element);
}
else if( type == DocumentApp.ElementType.INLINE_IMAGE ){
body.appendImage(element);
}
else if( type == DocumentApp.ElementType.HORIZONTAL_RULE ){
body.appendHorizontalRule();
}
else if( type == DocumentApp.ElementType.PAGE_BREAK ){
body.appendPageBreak();
}
else {
}
}
}
For some reason, whenever there is a footnote in the document, the script is unable to copy it over to another doc. To replicate what I'm doing, you can try using this document:
The script works with images, and basically everything else I put in my document.
It is possible that when running through each type of element (paragraph, table, list item, inline image, horizontal rule, and page break), it isn't able to recognize a footnote and just crashes? How can I have the program not crash when there's a footnote in the document?
I also wouldn't mind if the program was able to copy everything BUT the footnote... but for some reason it just crashes and doesn't copy anything over which is a concern I have for my project
ma...@gmail.com <ma...@gmail.com> #10
Thanks!!
va...@google.com <va...@google.com> #11
Hello Mathew,
Try adding targetDoc.saveAndClose()
after the for loop. It should save the target document will all the copied elements.
function speechDoc() {
var currentDoc = DocumentApp.getActiveDocument().getBody();
var targetDoc = DocumentApp.create('Speech Doc');
var totalElements = currentDoc.getNumChildren();
for( var index = 0; index < totalElements; ++index ) {
var body = targetDoc.getBody();
var element = currentDoc.getChild(index).copy();
var type = element.getType();
//Goes through each type of element and moves it to the new document titled 'Speech Doc'
if( type == DocumentApp.ElementType.PARAGRAPH ){
body.appendParagraph(element);
}
else if( type == DocumentApp.ElementType.TABLE){
body.appendTable(element);
}
else if( type == DocumentApp.ElementType.LIST_ITEM){
body.appendListItem(element);
}
else if( type == DocumentApp.ElementType.BOOKMARK ){
body.appendBookmark(element);
}
}
targetDoc.saveAndClose();
}
ma...@gmail.com <ma...@gmail.com> #12
Hello,
Unfortunately, after adding that line of code, the same error shows up (when trying to transfer a footnote)
Exception: Service Documents failed while accessing document with id 1y2m7i9qgFWdvWBahrWcwmJxBn91p-dcc9eccPMcyrF0.
at speechDoc(myProject:65:13)
Except now it points to line 65, which is the saveAndClose line that I just added.
is...@google.com <is...@google.com>
jp...@google.com <jp...@google.com>
in...@looplabz.com <in...@looplabz.com> #13
DocumentApp.openByUrl(destinationDocURL);
return Service Documents failed while accessing document with id ....
Please fix the issue
sa...@gmail.com <sa...@gmail.com> #14
when i run:
destinationBody.insertTable(paragraphIndex, sourceDocumentSectionHeaderTable)
cl...@gmail.com <cl...@gmail.com> #15
function myFunction() {
var sheet = SpreadsheetApp.getActiveSheet();
var charts = sheet.getCharts()[0];
Logger.log(sheet.getCharts()[0])
var chart = charts.modify()
.setOption('title', "updated")
.build()
sheet.updateChart(chart);
}
Same issue.
le...@paloaltonetworks.com <le...@paloaltonetworks.com> #16
yi...@lucence.com <yi...@lucence.com> #17
ro...@gmail.com <ro...@gmail.com> #18
ca...@c10.tech <ca...@c10.tech> #19
su...@quicklution.com <su...@quicklution.com> #20
Please assist urgently as millions of customers are being affected.
fr...@gmail.com <fr...@gmail.com> #21
jl...@lexpand.com <jl...@lexpand.com> #22
This started happening since yesterday.
al...@c.finwave.it <al...@c.finwave.it> #23
di...@xepelin.com <di...@xepelin.com> #24
fr...@gmail.com <fr...@gmail.com> #25
The workaround that I've managed to do is to split the documents into smaller chunks which helps but then it increases the execution time meaning we have to split this into multiple executions. There is a lot of trial and error. The whole process is extremely frustrating and timeconsuming.
el...@ben-hamu.com <el...@ben-hamu.com> #26
I was having a script that do a similar thing, create a new document and insert some dynamic data.
I use to use it several times a day for more than a year, and sudently from yesterday it stop working with the error message:
Exception: Service Documents failed while accessing document with id xxxxxxxxxxxx
As the previous reports also my script crash at: saveAndClose()
Please help
ti...@gmail.com <ti...@gmail.com> #27
el...@ben-hamu.com <el...@ben-hamu.com> #28
(Im inserting data in a table, when the table is smaller than 10 rows in the table is working fine, but if I add more it crashes).
But I reapat it use to work for over a year with more than 500 rows...
ti...@gmail.com <ti...@gmail.com> #29
ke...@gmail.com <ke...@gmail.com> #30
v....@gmail.com <v....@gmail.com> #31
ti...@gmail.com <ti...@gmail.com> #32
di...@talkdesk.com <di...@talkdesk.com> #33
jl...@lexpand.com <jl...@lexpand.com> #34
my...@gmail.com <my...@gmail.com> #35
As part of troubleshooting, I decided to manually copy and paste this data. After pasting to a blank test document, GDocs will automatically save the file. This operation should take no longer than 2 seconds, but now takes extremely long, and the operation ends up failing. It works, however, when copying only one page of tables (about 20 seconds). It takes considerably longer when doing 2 pages (40 seconds). There's something wrong with the save function.
se...@gmail.com <se...@gmail.com> #36
le...@gmail.com <le...@gmail.com> #37
da...@wuolle.com <da...@wuolle.com> #38
po...@gmail.com <po...@gmail.com> #39
re...@gmail.com <re...@gmail.com> #40
jl...@lexpand.com <jl...@lexpand.com> #41
fr...@gmail.com <fr...@gmail.com> #42
da...@wuolle.com <da...@wuolle.com> #43
[Deleted User] <[Deleted User]> #44
da...@wuolle.com <da...@wuolle.com> #45
as...@spherethat.ca <as...@spherethat.ca> #46
ro...@gmail.com <ro...@gmail.com> #47
ie I've just gone through the code and added .openById() and .saveAndClose() for specific document operations and it's "fixed" the error. The code now runs and exits without error.
go...@kay.id.au <go...@kay.id.au> #48
Resolved with getting the docId, reopening the doc and getting the body content.
gu...@gmail.com <gu...@gmail.com> #49
jp...@google.com <jp...@google.com> #50
Please see the correct issue for this,
Description
A short description of the issue:
My script takes the current document, and creates a copy of it (this is the first step to a bigger project). However, it returns an error since it is unable to ACCESS the document it creates, and copy over all elements from the current document.
A small code sample that reliably reproduces the issue. The sample should run as-is or with minimal setup, without external dependencies.
speechDoc();
function speechDoc() {
var currentDoc = DocumentApp.getActiveDocument().getBody();
var targetDoc = DocumentApp.create('Speech Doc');
var totalElements = currentDoc.getNumChildren();
for( var index = 0; index < totalElements; ++index ) {
var body = targetDoc.getBody();
var element = currentDoc.getChild(index).copy();
var type = element.getType();
//Goes through each type of element and moves it to the new document titled 'Speech Doc'
if( type == DocumentApp.ElementType.PARAGRAPH ){
body.appendParagraph(element);
}
else if( type == DocumentApp.ElementType.TABLE){
body.appendTable(element);
}
else if( type == DocumentApp.ElementType.LIST_ITEM){
body.appendListItem(element);
}
else if( type == DocumentApp.ElementType.BOOKMARK ){
body.appendBookmark(element);
}
}
}
What steps will reproduce the problem?
1. Run the program
2. A new doc will be created in your drive, but nothing from the current document will be added to it
3. The error message: Service Documents failed while accessing document with id [my target documents id] should pop up
What is the expected output? What do you see instead? If you see error messages, please provide them.
I expect there to be a new document created in my google drive, called 'Speech Doc,' and all the elements from my current document transferred over to my target document, 'Speech Doc.'
Instead, I see a new document called 'Speech Doc' but no elements transferred over.
I also see this error message:
Service Documents failed while accessing document with id [my target documents id]
Please provide any additional information below:
I changed the scopes of my script so that it has access to all of my documents. That didn't help. I also checked on stack overflow and I saw a similar question; with no answers.
This literally worked perfectly yesterday, and then it suddenly stopped working. Could this be a glitch in google servers or something???