In general i want people to put some data into a google sheet and provide a button, which takes the data and automatically fills a prefabricated google slide. I have chosen the approach to duplicate a master slide and then replacing individual text modulars with the data. Is there a better approach for my goal?
This is the Master-Slide
This is the code i use for the duplication, but it is only able to duplicate the master slide once, because the objectId it creates, is always the same: "copiedSlide_001". I have tried to use a random integer for the objectId, but i dont get it to work. Also, i guess the name has to be predictable to be used in the next step. (importing the data into newly copied slide).
function duplicateSlide() {
var presentationId = "1XLtOv7FHWwv6R2QEZF_LEhF7twXTlY3IbvsVDKxdDtc";
var pageId = "g75e5d89173_0_0"
var requests = [{
"duplicateObject": {
"objectId": pageId,
"objectIds": {
"g75e5d89173_0_0": "copiedSlide_001",
}
}
} ]Slides.Presentations.batchUpdate({'requests': requests}, presentationId);
}
How do i get the duplication process to work in my favor?
I would appreciate any help highly!
copiedSlide_001
.
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
Before you run the script, please enable Slides API at Advanced Google services.
function duplicateSlide() {
var presentationId = "1XLtOv7FHWwv6R2QEZF_LEhF7twXTlY3IbvsVDKxdDtc"; // Please set the Slides ID.
var pageId = "g75e5d89173_0_0"; // Please set the page ID of the source slide.
var newIDs = ["copiedSlide_001", "copiedSlide_002", "copiedSlide_003"]; // Please set the unique ID here.
var requests = newIDs.reverse().map(function(id) {
var obj = {};
obj[pageId] = id;
return {duplicateObject: {objectId: pageId, objectIds: obj}};
});
// requests.push({deleteObject: {objectId: pageId}});
Slides.Presentations.batchUpdate({'requests': requests}, presentationId);
}
requests.push({deleteObject: {objectId: pageId}});
, after the copy was finished, the 1st page, which is the source slide, is deleted. But I'm not sure whether this is the result you want. So I put it in the script as a comment.If I misunderstood your question and this was not the direction you want, I apologize.