Last active
September 7, 2018 18:27
-
-
Save stmcallister/dfbd7d6ae68e6ccf7d5c1eef41d5f0a6 to your computer and use it in GitHub Desktop.
Adding a row that contains a cell with a PREDECESSOR_LIST type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import smartsheet | |
import os | |
import json | |
import datetime | |
ss_client = smartsheet.Smartsheet(os.environ['SMARTSHEET_ACCESS_TOKEN']) | |
ss_client.errors_as_exceptions() | |
sheet_ID = 2089332342318980 | |
try: | |
newRowsToCreate = [] | |
rowObject = ss_client.models.Row() | |
rowObject.toTop = True | |
# create label cell | |
rowObject.cells.append({ | |
'column_id': 3451460777207684, | |
'value': "Python Task With Pred and start date and duration" | |
}) | |
# create start_date cell | |
rowObject.cells.append({ | |
'column_id': 7955060404578180, | |
'value': str(datetime.date(2018,11,13)) | |
}) | |
# create duration cell | |
rowObject.cells.append({ | |
'column_id': 7392110451156868, | |
'value': '1d' | |
}) | |
# initialize PredecessorList and Predecessor objects | |
pred_list = ss_client.models.PredecessorList() | |
pred = ss_client.models.Predecessor() | |
# populate Predecessor object | |
pred.row_id = 1935176806754180 | |
pred.type = "SF" | |
# init and populate predecessor array with Predecessor object | |
pred_array = [] | |
pred_array.append(pred) | |
pred_list.predecessors = pred | |
# init Cell object for predecessor cell | |
pred_cell = ss_client.models.Cell() | |
pred_cell.column_id = 6266210544314244 | |
# 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 | |
rowObject.cells.append(pred_cell) | |
newRowsToCreate.append(rowObject) | |
# Add rows to sheet | |
response = ss_client.Sheets.add_rows( | |
sheet_ID, # sheet_id | |
newRowsToCreate) | |
print(response) | |
except smartsheet.exceptions.SmartsheetException as e: | |
# SmartsheetException is the base class for all of the exceptions raised by the SDK. | |
# The two most common types of SmartsheetException are ApiError and HttpError. After trapping the exception, first | |
# determine the exception type using an 'isinstance' test. | |
# | |
# In this example, the ApiError exception has an Error class object accessible through the 'error' property, and | |
# then that in turn points to an ErrorResult class accessible through the result property. | |
# | |
# The details of the API error are stored in that ErrorResult. | |
if isinstance(e, smartsheet.exceptions.ApiError): | |
print(e.error.result.error_code) | |
print(e.error.result.message) | |
print(e.error.result.name) | |
print(e.error.result.recommendation) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment