2

I have a loop that creates a parent row and a variable number of child rows. I would like to update the Predecessor field of the child row with the prior child row number (when more than one child row is added). I am having difficulty adding the 2 required arguments to the 'cell.object_value' object (object_type & predecessors).

for key, value in record.items():    
    new_cell = ss.models.Cell()
    if k == 'Predecessors':
        pred = []
        pred_update = {}
        pred_update['rowId'] = predecessor_row_id
        pred_update['type'] = 'FS'
        pred.append(pred_update)

        row = ss.Sheets.get_row(sheet_id, predecessor_row_id)
        new_cell.object_value = str(row.row_number)
        new_cell.object_value.predecessors = pred
        new_cell.object_type = "PREDECESSOR_LIST"

EDIT: The code runs without error however the information contained in the new_cell.object_value.predecessors argument is not being transferred into SmartSheet.

2 Answers2

3

Setting predecessors is little tricky. You were on the right track. However, when you set the value on the cell, you just need to set the object_value. Like this:

# init the object_value for predecessor cell
pred_cell.object_value = ss_client.models.ObjectValue()

# set the object_type to PREDECESSOR_LIST
pred_cell.object_value.object_type = "PREDECESSOR_LIST"

# set the object_value for the cell with the PredecessorList
pred_cell.object_value = pred_list

A full Gist of the operation can be found here.

stmcallister
  • 1,682
  • 1
  • 12
  • 21
1

predecessors is a property of the object value, not the cell directly.

new_cell.objectValue.predecessors = pred
Software2
  • 2,358
  • 1
  • 18
  • 28
  • Thanks, you have helped me get one step closer. However, I am still having an issue setting the object_type which I believe is preventing the predecessor field from having its intended effect on the timeline. – Michael Williams Aug 22 '18 at 01:43