Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

smartsheet api - How to create a project sheet via the 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.

Here is my code so far:

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

I am getting the following error code:

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?

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

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

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().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...