如何通过python SDK创建项目表 [英] How to create a project sheet via the python SDK

查看:44
本文介绍了如何通过python SDK创建项目表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在文件夹中创建新的项目工作表,但是我找不到确保该工作表是项目工作表的方法.

I'm trying to create new project sheets in a folder, however I can't find a way to ensure the sheet is a project sheet.

这是我目前的代码:

def create_resource_sheet(name):
    """ Create a new resource sheet.

    :param name:
    :return:
    """
    folder_id = get_resource_folder_id()

    # TODO: Find and delete existing sheet with this name

    resource_sheet = SS.models.Sheet({
        'name': name,
        # 'gantt_enabled': True,  # This was added as an attempt to force it to a project sheet, but error 1032
        'columns': [{
            'title': 'Task',
            'type': 'TEXT_NUMBER',
            'primary': True,
            'width': 200
        }, {
            'title': 'Status',
            'type': 'PICKLIST',
            'options': ['wtg', 'hld', 'ip', 'rdy', 'rev', 'fin', 'omt'],  # TODO: Update this list
            'width': 180
        }, {
            'title': '% Complete',
            'type': 'TEXT_NUMBER',
            'tag': ['GANTT_PERCENT_COMPLETE'],
            'width': 85
        }, {
            'title': 'Assigned To',
            'type': 'CONTACT_LIST',
            'tag': ['GANTT_ASSIGNED_RESOURCE', 'GANTT_DISPLAY_LABEL'],
            'width': 150
        }, {
            'title': '% Use',
            'type': 'TEXT_NUMBER',
            'tag': ['GANTT_ALLOCATION'],
            'width': 60
        }, {
            'title': 'Days',
            'type': 'DURATION',
            'tag': ['GANTT_DURATION'],
            'width': 70
        }, {
            'title': 'Start',
            'type': 'ABSTRACT_DATETIME',
            'tag': ['CALENDAR_START_DATE', 'GANTT_START_DATE'],
            'width': 80
        }, {
            'title': 'Start',
            'type': 'ABSTRACT_DATETIME',
            'tag': ['CALENDAR_START_DATE', 'GANTT_START_DATE'],
            'width': 80
        }, {
            'title': 'Finish',
            'type': 'ABSTRACT_DATETIME',
            'tag': ['CALENDAR_END_DATE', 'GANTT_END_DATE'],
            'width': 80
        }, {
            'title': 'Type',
            'type': 'TEXT_NUMBER',
            'width': 150
        }, {
            'title': 'Comments',
            'type': 'TEXT_NUMBER',
            'width': 700
        }
        ]
    })

    response = SS.Folders.create_sheet_in_folder(folder_id, resource_sheet)
    new_sheet = response.result
    return new_sheet

我收到以下错误代码:

smartsheet.exceptions.ApiError: {"result": {"shouldRetry": false,代码":1142,名称":ApiError",错误代码":1142,推荐":"不要在没有解决问题的情况下重试.", "message": "列类型DURATION 为项目表保留,不能手动设置一列.", "refId": "6gurrzzwhepe", "statusCode": 400}}

smartsheet.exceptions.ApiError: {"result": {"shouldRetry": false, "code": 1142, "name": "ApiError", "errorCode": 1142, "recommendation": "Do not retry without fixing the problem. ", "message": "Column type DURATION is reserved for project sheets and may not be manually set on a column.", "refId": "6gurrzzwhepe", "statusCode": 400}}

有没有办法从头开始创建项目表?

Is there a way I can create project sheets from scratch?

我已经尝试将 gantt_enabled 设置为 true 但这只是触发了一个不同的错误,设置project_settings"也是如此.

I have tried setting gantt_enabled to true but that just triggered a different error, so did setting 'project_settings'.

我曾尝试仅使用主列创建工作表,然后使用 update_sheet 设置项目设置,它告诉我:要设置 projectSettings,您必须首先启用工作表上的依赖项.

I have tried creating the sheet with just the primary column, then update_sheet to set project settings, which tells me: To set projectSettings, you must first enable dependencies on the sheet.

我尝试直接在 create_sheet 和 update_sheet 中设置依赖项启用,但都返回:此操作不允许使用属性 sheet.dependenciesEnabled.

I have tried setting dependencies enabled, both directly in the create_sheet and in update_sheet, but both return: The attribute(s) sheet.dependenciesEnabled are not allowed for this operation.

我会继续尝试,但我已经没有想法了.

I'm going to keep trying things, but I'm getting out of ideas.

推荐答案

从模板创建工作表,如果要自定义,可以使用全局项目模板或用户定义的模板.

Create the sheet from a template, either using the global project template or a user defined template if you want to customize.

templates = SS.Templates.list_public_templates()
for template in templates.data:
    if template.global_template == 
smartsheet.models.enums.GlobalTemplate.PROJECT_SHEET:
    break
sheet = smartsheet.models.Sheet({
    'name': name,
    'from_id': template.id
})
resource_sheet = SS.Folders.create_sheet_in_folder(folder_id, sheet)

如果要使用 Smartsheet Web UI 自定义创建项目表,请进行更改,然后另存为模板.获得模板后,如果您不想搜索它,请从属性中获取 ID,或者 SS.Templates.list_user_created_templates().

If you want to customize create a project sheet using the Smartsheet web UI, make your changes and then Save As Template. Once you have the template, grab the ID from the Properties if you don't want to search for it, or SS.Templates.list_user_created_templates().

这篇关于如何通过python SDK创建项目表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆