'simple-salesforce - How to create Knowledge Page Layout programatically?

I've been able to create a Record Type and Custom Field for the Knowledge module of Salesforce with the metadata api implemented in simple-salesforce's python library, but when trying to create a Page Layout it throws an exception without much info on why is the creation failing (or at least I don't get it).

I'm trying to create the page layout in the following way:

def create_page_layout(self, layout_name, fields):
        mdapi = self.sf.mdapi
        # custom_layout_section = []
        custom_layout_items = []

        for field in fields:
            custom_layout_items.append(mdapi.LayoutItem(
                field=field
            ))

        custom_layout_section = [mdapi.LayoutSection(
            label='Information',
            style='OneColumn',
            layoutColumns=mdapi.LayoutColumn(
                layoutItems=custom_layout_items
            )
        )]

        custom_layout = mdapi.Layout(
            fullName='Knowledge__kav.' + layout_name + '__c',
            layoutSections=custom_layout_section
        )
        mdapi.Layout.create(custom_layout)

The param layout_name contains 'TestDefaultPL'.

The param fields contains ['Title', 'UrlName'].

The exception: Exception: Knowledge__kav.TestDefaultPL__c: (FIELD_INTEGRITY_EXCEPTION, Parent entity failed to deploy).

The docs about this object: link.

As an example, I was able to create a custom field for the Knowledge module in the following way:

def create_custom_field(self, name):
        mdapi = self.sf.mdapi
        # TODO: Field permissions
        custom_field = mdapi.CustomField(
            label=name,  # Field label
            fullName='Knowledge__kav.' + name + '__c',  # Field name (format has to be CustomObject.FieldName)
            type=mdapi.FieldType("LongTextArea"),
            length=32000,
            description='Default Rich Text Area',
            visibleLines=25
        )
        return mdapi.CustomField.create(custom_field)

Could someone help me with this problem about the Page Layout creation?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source