Writing to a multi-picklist using the smartsheet-python-SDK

62 Views Asked by At

Im trying to write to a cell in smartsheet which is in a multi-picklist column. I'm updating the value but the error message is telling me its missing the attribute cell.value

{"response": {"statusCode": 400, "reason": "Bad Request", "content": {"detail": {"index": 0, "rowId": 3036099537571716}, "errorCode": 1012, "message": "Required object attribute(s) are missing from your request: cell.value.", "refId": "qo1kjj"}}}

Through some print statements I know the variable is updating, and this code works on normal columns.

workspace_name = 'API TEST'
sheet_name = 'test sheet'
lookup_value = 'b'
write_value = 'A'

write_column = 'first column'
lookup_column = 'multi picklist'

smart = init_smartsheet()
sheet_data, sheet_id = init_sheet(workspace_name, sheet_name, client)

write_column_id = sheet_data.get_column_by_title(write_column).id_
lookup_column_id = sheet_data.get_column_by_title(lookup_column).id_

updated_row = None
for row in sheet_data.rows:
    for cell in row.cells:
        if cell.column_id == lookup_column_id and cell.value == lookup_value:
            updated_row = row
            break
    if updated_row:
        break

for cell in updated_row.cells:
    if cell.column_id == write_column_id:
        cell.value = write_value
        break

updated_row.created_at = None
updated_row.modified_at = None
updated_row.row_number = None
updated_row.below = True


smart.Sheets.update_rows(sheet_id, [updated_row])```
1

There are 1 best solutions below

0
On

Try this format

import smartsheet

smartsheetClient = smartsheet.Smartsheet('smartsheet token')
sheetid = 'sheet id'
sheet = smartsheetClient.Sheets.get_sheet(sheetid)

listOptions = ["bob","joe","sally", "matilda"]

column_name = "MultiColumnName"

for column in sheet.columns:
    if column.title == column_name:
        columnid = column.id
        break

cs=smartsheet.models.Column({

        'title':"columnTitle",
        'type':'PICKLIST',
        'options': listOptions,
        'index':2,
        'validation': True
        })

r=smartsheetClient.Sheets.update_column(sheetid,columnid,cs)

make sure the index is the index associated with the column which the picklist is