Get Layout's display name of a Google Presentation Slide via Google Apps Scripts

Viewed 462

I am trying to append a new slide to my presentation with a created layout via Google Apps Scripts.

I started a new presentation, created two new layouts, named them as 'BulletDescription' and 'TextDescription'. I can get all the layouts available in the presentation. However, I can't find the layouts which I manually created by their names.

function AddNewSlideToPresentation(LayoutType) //LayoutType = 'BulletDescription'
{ 
  var presentation = SlidesApp.openById('PresentationID');
  var layouts = presentation.getLayouts();
  var selectedLayout;
  for(var item in layouts)
  {
    Logger.log(layouts[item].getLayoutName());
    if(layouts[item].getLayoutName() == LayoutType)
    {
      selectedLayout = layouts[item];
    }
  }

  var newSlide = presentation.appendSlide(selectedLayout); // this returns an error
}

It seems that .getLayoutName() function gives us different name as I found on my log;

TITLE
SECTION_HEADER
TITLE_AND_BODY
MAIN_POINT
.
.
CUSTOM_1
CUSTOM_2

I believe CUSTOM_1 and CUSTOM_2 are the ones I created. Is there a way to get display name of the layout via Google Apps Script?

1 Answers

Try this to get layout name from LayoutProperties:

if (layouts[item].layoutProperties.displayName == LayoutType)
{
    // found needed layout..
}
Related