Trying to duplicate 3 (could be more, depending on the presentation) slides multiple times.
After searching have found a close result: Google Slide API-How do i duplicate a slide several times and creating a unique object id each time, however does not allow for a third slide.
Code so far is as follows:
function duplicateSlide() {
var presentationId = "1J14grlx5pMrcsglMvmDVB22vTf89Qt0JUaq394Rltfc"; // Please set the Slides ID.
var pageId1 = "g1399daed6c0_0_89"; // Please set the page ID of the source slide.
var pageId2 = "g1399daed6c0_0_9"; // Please set the page ID of the source slide.
var pageId3 = "g1399daed6c0_0_15"; // Please set the page ID of the source slide.
var newID1 = ["First_1", "First_2", "First_3", "First_4"]; // Please set the unique ID here."
var newID2 = ["Second_1A", "Second_2B", "Second_3C", "Second_4D"]; // Please set the unique ID here."
var newID3 = ["Third_1A1", "Third_2B2", "Third_3C3", "Third_4D4"]; // Please set the unique ID here."
var requests = newID1.reverse().map(function(id) {
var obj = {};
obj[pageId1] = id;
return {duplicateObject: {objectId: pageId1, objectIds: obj}};
});
var requests = newID2.reverse().map(function(id) {
var obj = {};
obj[pageId2] = id;
return {duplicateObject: {objectId: pageId2, objectIds: obj}};
});
var requests = newID3.reverse().map(function(id) {
var obj = {};
obj[pageId3] = id;
return {duplicateObject: {objectId: pageId3 , objectIds: obj}};
});
// requests.push({deleteObject: {objectId: pageId}});
Slides.Presentations.batchUpdate({'requests': requests}, presentationId);
}
Thank you
CodePudding user response:
In your script, only 3rd requests
is used. Because the 1st requests
is overwritten by 2nd requests
, and the 2nd requests
is overwritten by 3rd requests
. If you want to include all requests, how about the following modification?
From:
var requests = newID1.reverse().map(function(id) {
var obj = {};
obj[pageId1] = id;
return {duplicateObject: {objectId: pageId1, objectIds: obj}};
});
var requests = newID2.reverse().map(function(id) {
var obj = {};
obj[pageId2] = id;
return {duplicateObject: {objectId: pageId2, objectIds: obj}};
});
var requests = newID3.reverse().map(function(id) {
var obj = {};
obj[pageId3] = id;
return {duplicateObject: {objectId: pageId3 , objectIds: obj}};
});
To:
var requests1 = newID1.reverse().map(function (id) {
var obj = {};
obj[pageId1] = id;
return { duplicateObject: { objectId: pageId1, objectIds: obj } };
});
var requests2 = newID2.reverse().map(function (id) {
var obj = {};
obj[pageId2] = id;
return { duplicateObject: { objectId: pageId2, objectIds: obj } };
});
var requests3 = newID3.reverse().map(function (id) {
var obj = {};
obj[pageId3] = id;
return { duplicateObject: { objectId: pageId3, objectIds: obj } };
});
var requests = [...requests1, ...requests2, ...requests3];