Google Slides: Page, Duplicate
Google Slides: Page, Duplicate
Duplicates the specified slide page and inserts it on the next page. If no page is specified, the last page will be duplicated. It is used when you want to start by duplicating a template page, such as creating a header image or a summary report.
Configs
  • U: Select HTTP_Authz Setting *
  • A: Set FILE-ID in Drive *#{EL}
  • B1: Set Object-ID of Slide Page (Chars following “id.”)#{EL}
  • B2: Select STRING DATA for Object-ID of New Slide Page (update)
Script (click to open)
// GraalJS Script (engine type: 2)

//////// START "main()" /////////////////////////////////////////////////////////////////

main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const strAuthzSetting     = configs.get      ( "AuthzConfU" );   /// REQUIRED
  engine.log( " AutomatedTask Config: Authz Setting: " + strAuthzSetting );
const strInputfileId      = configs.get      ( "StrConfA1" );    /// REQUIRED
  if( strInputfileId    === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {A1: FileID} is empty \n" );
  }
let   strPageidOriginal   = configs.get      ( "StrConfB1" );    // NotRequired
const strPocketPageidNew  = configs.getObject( "SelectConfB2" ); // NotRequired


//// == Data Retrieving / ワークフローデータの参照 ==
// (Nothing. Retrieved via Expression Language in Config Retrieving)


//// == Calculating / 演算 ==

/// Get LastPage ID
/// Google Slides API
/// https://developers.google.com/slides/reference/rest/v1/presentations/get

if( strPageidOriginal === "" ){
  // request0, prepare
  let request0Uri = "https://slides.googleapis.com/v1/presentations/" + strInputfileId;
  let request0    = httpClient.begin(); // HttpRequestWrapper
      request0    = request0.authSetting( strAuthzSetting ); // with "Authorization: Bearer XX"
      // https://questetra.zendesk.com/hc/en-us/articles/360024574471-R2300#HttpRequestWrapper
  // request0, try
  const response0 = request0.get( request0Uri ); // HttpResponseWrapper
  engine.log( " AutomatedTask ApiRequest0 Start: " + request0Uri );
  const response0Code = response0.getStatusCode() + "";
  const response0Body = response0.getResponseAsString() + "";
  engine.log( " AutomatedTask ApiResponse Status: " + response0Code );
  if( response0Code !== "200"){
    throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                      response0Code + "\n" + response0Body + "\n" );
  }
  // response0, parse
  const response0Obj = JSON.parse( response0Body );
  strPageidOriginal = response0Obj.slides[ response0Obj.slides.length - 1 ].objectId;
}

/// Duplicate the Page (via batchUpdate Request)
/// Google Slides API
/// https://developers.google.com/slides/reference/rest/v1/presentations/request#duplicateobjectrequest

// request1, prepare
let request1Uri = "https://slides.googleapis.com/v1/presentations/" +
                  strInputfileId + ":batchUpdate";
let request1Obj = {};
    request1Obj.requests = [];
    request1Obj.requests[0] = {};
    request1Obj.requests[0].duplicateObject = {};
    request1Obj.requests[0].duplicateObject.objectId = strPageidOriginal;
let request1    = httpClient.begin(); // HttpRequestWrapper
    request1    = request1.authSetting( strAuthzSetting ); // with "Authorization: Bearer XX"
    // https://questetra.zendesk.com/hc/en-us/articles/360024574471-R2300#HttpRequestWrapper
    request1    = request1.body( JSON.stringify( request1Obj ), "application/json" );
// request1, try
const response1     = request1.post( request1Uri ); // HttpResponseWrapper
engine.log( " AutomatedTask ApiRequest1 Start: " + request1Uri );
const response1Code = response1.getStatusCode() + "";
const response1Body = response1.getResponseAsString() + "";
engine.log( " AutomatedTask ApiResponse Status: " + response1Code );
if( response1Code !== "200"){
  throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                    response1Code + "\n" + response1Body + "\n" );
}
// response1, parse
/* 
engine.log( response1Body ); // debug
{
  "presentationId": "1oDCufkoKg3LQeaqBVs5VA0xX3k2d5GxhH8tvmcIXeV4",
  "replies": [
    {
      "duplicateObject": {
        "objectId": "SLIDES_API1432471875_0"
      }
    }
  ],
  "writeControl": {
    "requiredRevisionId": "ssjMIIo3IRFIFg"
  }
}
*/
const response1Obj = JSON.parse( response1Body );
const strPageidNew = response1Obj.replies[0].duplicateObject.objectId;


//// == Data Updating / ワークフローデータへの代入 ==
engine.setData( strPocketPageidNew,    strPageidNew );


} //////// END "main()" /////////////////////////////////////////////////////////////////


/*
Notes:
- You can build a system to automatically duplicate template page or last page. GoogleSlidesDuplicate
- For example, if you want to automate the notification of "Monthly Sales Report", define as follows:
    - The template page is automatically duplicated (Google Slides: Page, Duplicate)
    - The report text part is automatically replaced (Google Slides: Page, Replace Strings)
    - The embedded graph is automatically updated (Google Slides: Page, Refresh Charts)
    - The slide page is automatically converted to a PNG image (Google Slides: Page, Generate PNG)
    - The email with the PNG image attached will be sent automatically. (ThrowEmail Event)
Notes-ja:
- Googleスライド内の雛形ページや末尾ページが自動複製される仕組みを構築できます。GoogleSlidesDuplicate
- たとえば「月次売上レポート」の通知業務を自動化したい場合は、以下のような業務プロセスを定義します。
    - 雛形ページが自動複製され、(※Google スライド: ページ, 複製)
    - 貼り付けられている埋め込みグラフが自動更新され、(※Google スライド: ページ, 文字列全置換)
    - 報告テキスト部が当月文に自動置換され、(※Google スライド: ページ, 全グラフ更新)
    - 当該スライドページがPNG画像に自動変換され、(※Google スライド: ページ, PNG画像生成)
    - PNG画像が添付されたメールが自動的に送信される。(※ ThrowEmail イベント)

APPENDIX-en
- FILE-ID/PresentationID in Drive (Chars following "/d/")
    - docs.google.com/presentation/d/1p33hGJFUNYixBmMeaV81nsOVYGUUrZIFyErinFp3CI8
- Object-ID of Slide Page (Chars following "id.")
    - docs.google.com/presentation/d/1p33hGJFUNYixBmMeaV81nsOVYGUUrZIFyErinFp3CI8/edit#slide=id.g613777c84a_0_0
- Setting example of "HTTP Authentication" (OAuth2)
    - Authorization Endpoint URL:
        - https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force
    - Token Endpoint URL:
        - https://accounts.google.com/o/oauth2/token
    - Scope:
        - https://www.googleapis.com/auth/presentations
    - Client ID, Consumer Secret:
        - ( from https://console.developers.google.com/ )
        - Redirect URLs: https://s.questetra.net/oauth2callback
APPENDIX-ja
- FILE-ID/PresentationID in Drive ("/d/" 以降の文字列)
    - docs.google.com/presentation/d/1p33hGJFUNYixBmMeaV81nsOVYGUUrZIFyErinFp3CI8
- Object-ID of Slide Page ("id." 以降の文字列)
    - docs.google.com/presentation/d/1p33hGJFUNYixBmMeaV81nsOVYGUUrZIFyErinFp3CI8/edit#slide=id.g613777c84a_0_0
- "HTTP認証"(OAuth2)の設定例
    - Authorization Endpoint URL:
        - https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force
    - Token Endpoint URL:
        - https://accounts.google.com/o/oauth2/token
    - Scope:
        - https://www.googleapis.com/auth/presentations
    - Client ID, Consumer Secret:
        - ( from https://console.developers.google.com/ )
        - Redirect URLs: https://s.questetra.net/oauth2callback
*/

Download

2021-05-15 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/google-slides-page-duplicate-2021/
The Addon-import feature is available with Professional edition.

Notes

  • You can build a system to automatically duplicate template page or last page. GoogleSlidesDuplicate
  • For example, if you want to automate the notification of “Monthly Sales Report”, define as follows:
    • The template page is automatically duplicated (Google Slides: Page, Duplicate)
    • The report text part is automatically replaced (Google Slides: Page, Replace Strings)
    • The embedded graph is automatically updated (Google Slides: Page, Refresh Charts)
    • The slide page is automatically converted to a PNG image (Google Slides: Page, Generate PNG)
    • The email with the PNG image attached will be sent automatically. (ThrowEmail Event)

Capture

Duplicates the specified slide page and inserts it on the next page. If no page is specified, the last page will be duplicated. It is used when you want to start by duplicating a template page, such as creating a header image or a summary report.
Duplicates the specified slide page and inserts it on the next page. If no page is specified, the last page will be duplicated. It is used when you want to start by duplicating a template page, such as creating a header image or a summary report.

Appendix

See also

5 thoughts on “Google Slides: Page, Duplicate”

  1. Pingback: Google Slides: Page, Replace Strings – Questetra Support

  2. Pingback: Google Slides: Page, Refresh Charts – Questetra Support

  3. Pingback: Google Slides: Page, Export as PNG – Questetra Support

  4. Pingback: Google Slides: Page; Duplicate – Questetra Support

  5. Pingback: Understanding HTTP Authorization Settings – Questetra Support

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: