How do i add a comment to a particular google slide using app script
I have a google slide desk with three slides & i want to add a comment to each slide. I am able to reach to the slide using for loop (total rows in sheet is same as total number of slides, and slide i am using is the second slide onwards. so there is no problem with my loop)
// open the slide using slide id
var s=SlidesApp.openById(a.getId())
for(let r=2; r<=4; r++){
// get the current slide
var currentSlide=s.getSlides()[r-1];
var fileId = currentSlide.getObjectId();
var slideUrl = a.getUrl()+"#slide=id."+fileId;
var slideId = getIdFromUrl(slideUrl);
var comment = {'content':'hi'};
Drive.Comments.insert(comment, slideId);
}
function getIdFromUrl(url) { return url.match(/[-\w]{25,}/); }
This code works but its adding the comment to the file and not to the individual slide. (*Note - For this code to work, we have to enable Drive in services in app script.) How can i add the comment to the individual slides.
Answer:
Not possible.
Explanation:
It is currently not possible to add comments to a specific location in Google Documents (including Docs, Sheets, Slides). The ability for adding anchored comments refers to non-Google Docs (e.g. images, PDFs) (listen to this video for more details).
Therefore, you can only add comments unanchored comments, belonging to the whole file.
What's possible is responding to a located comment by retrieving its id
and calling Replies: create.
Issue Tracker:
There are several feature requests for this in Issue Tracker, either about all of Google Docs editors or about a specific editor:
- Provide read/write access to comments in Google Docs
- Ability to create comments in specific cells/ranges and assign them to someone
- Provide ability to create a Drive API Comment anchor resource as method on DocumentApp selection class
I'd suggest you to subscribe to some or all of these issues by starring them and/or file a new feature request to tackle Slides specifically.
Related questions:
- Creating anchored comments programmatically in Google Docs
- Google Drive API ignores anchor parameter when creating comments in a spreadsheet
- How to match comments on an image using kix anchor (or not) in Google Docs