Use data from one grid to fill master grid

Please consider this scenario:

I'd like to update the data available in Grid 1 to a grid called Grid M. Considering that Grid M might have previous values, I'd like to overwrite them with Grid 1's data.

I prefer overwriting instead of adding or copying rows because I want to use this Grid M as a master file that copies everything that is located in Grid 1, so previous typos, changes, won't matter, only the actual data that shows Grid 1. Do note that structure is the same for both sheets.

Consider the following code:

# Grids grid1 = 6975487445624708 gridM = 4175140851345284 # Initialize get sheet properties / get columns readSheet_Grid1 = smart.Sheets.get_sheet(grid1) readColumn_Grid1 = readSheet_Grid1.get_columns().data readSheet_GridM = smart.Sheets.get_sheet(gridM) readColumn_GridM = readSheet_GridM.get_columns().data # Get Columns ID from Grid 1 columntoRead = [] for column in readColumn_Grid1: columntoRead.append(column.id) print(columntoRead)

This is the output containing column IDs within lists.

[7236841595791236, 1607342061578116, 6110941688948612, 8503502613309316, 3999902985938820, 3859141875263364, 8362741502633860, 1044392108156804]

Getting cell values

# Get values celltoRead = [] for MyRow in readSheet_Grid1.rows: for MyCell in MyRow.cells: if MyCell.column_id == columntoRead: if (MyCell.value): celltoRead.append(MyCell.value) print(MyCell)

This is the output (sample data):

{"columnId": 7236841595791236, "displayValue": "3240099", "value": 3240099.0} {"columnId": 1607342061578116, "displayValue": "James", "value": "James"} {"columnId": 6110941688948612, "displayValue": "Hamilton", "value": "Hamilton"} {"columnId": 8503502613309316, "displayValue": "Male", "value": "Male"} {"columnId": 3999902985938820, "displayValue": "197556", "value": 197556.0} {"columnId": 3859141875263364, "displayValue": "18", "value": 18.0} {"columnId": 8362741502633860, "displayValue": "Bachelor", "value": "Bachelor"} {"columnId": 1044392108156804, "displayValue": "Medic", "value": "Medic"} {"columnId": 7236841595791236, "displayValue": "9615534", "value": 9615534.0} {"columnId": 1607342061578116, "displayValue": "Miranda", "value": "Miranda"} {"columnId": 6110941688948612, "displayValue": "Montgomery", "value": "Montgomery"} {"columnId": 8503502613309316, "displayValue": "Female", "value": "Female"} {"columnId": 3999902985938820, "displayValue": "158585", "value": 158585.0} {"columnId": 3859141875263364, "displayValue": "20", "value": 20.0} {"columnId": 8362741502633860, "displayValue": "Primary", "value": "Primary"} {"columnId": 1044392108156804, "displayValue": "Historian", "value": "Historian"} etc,

Above snippet is mostly for reference. Note that this grid contains 8 columns, starting from this ColumnId 7236841595791236, and ending with this one 1044392108156804.

现在,我想乌利希期刊指南ate rows in Grid M with data from Grid 1 by usingupdate_rows(sheet_id, list_of_rows), but I can't wrap my head around mapping the necessary steps to build it.

I think there are two things I need to know to accomplish this task (and would like your insights on how to tackle them).

  • One, look for a way to "translate" the columns IDs from Grid 1 to Grid M, maybe creating a function pairing those values with if conditions (?
  • Two, mapping column and cell in a way that these values are considered when using the update_rows function.

Sorry if my question is confusing, I'm still a beginner in Python and data structures in general.

Answers

  • Emilio Wright
    Emilio Wright ✭✭✭
    edited 02/02/23

    lschek1,


    A couple of things:

    • I don't believe column IDs will be the same across sheets, so assuming both sheets have the same name columns, I would create a column map so that you can get the column id on both sheets and match the data that you will be updating
    • I have provided my answer below assuming that grid 1 and grid M will always have the same number of rows. If Grid M has fewer rows than Grid 1, you will run out of rows in the loop to update. You will then have to create brand new rows. If it is the other way around, you will have to delete any remaining rows to keep both sheets consistent.
    readSheet_Grid1 = smart.Sheets.get_sheet(grid1) columnMapGrid1 = {} for column in readSheet_Grid1.columns: columnMap[column.title] = column.id
    image.png


    In my experience with updating values inside sheets with the API, I found that you will first need to build the cell you want to update, then build the row, and finally update the row.

    #snippet from Smartsheet.redoc.ly for Update Row # Build new cell value new_cell = smartsheet.models.Cell() new_cell.column_id = 7036894123976580 new_cell.value = "new value" new_cell.strict = False # Build the row to update new_row = smartsheet.models.Row() new_row.id = 6809535313667972 new_row.cells.append(new_cell) # Update rows updated_row = smartsheet_client.Sheets.update_rows( 2068827774183300, # sheet_id [new_row])


    Let me know if this helps. I can always answer a bit more.

You cannot sent an update request via API to text.<\/p>"}]}},"status":{"statusID":3,"name":"Accepted","state":"closed","recordType":"discussion","recordSubType":"question"},"bookmarked":false,"unread":false,"category":{"categoryID":320,"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers","allowedDiscussionTypes":[]},"reactions":[{"tagID":3,"urlcode":"Promote","name":"Promote","class":"Positive","hasReacted":false,"reactionValue":5,"count":0},{"tagID":5,"urlcode":"Insightful","name":"Insightful","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":11,"urlcode":"Up","name":"Vote Up","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":13,"urlcode":"Awesome","name":"Awesome","class":"Positive","hasReacted":false,"reactionValue":1,"count":1}],"tags":[{"tagID":227,"urlcode":"api-and-developers","name":"API and Developers"}]},{"discussionID":108829,"type":"question","name":"Power automate question (multi-contact list)","excerpt":"I'm using power automate to wire up some info into smartsheets. I have everything working so far but multi contact list and multi pick list. The contact list error I get is this: The value \"John smith\" could not be saved in column \"Assignment\". This column is restricted to MULTI_CONTACT_LIST values only. The name is…","snippet":"I'm using power automate to wire up some info into smartsheets. I have everything working so far but multi contact list and multi pick list. The contact list error I get is this:…","categoryID":320,"dateInserted":"2023-08-10T23:21:44+00:00","dateUpdated":"2023-08-11T08:46:38+00:00","dateLastComment":"2023-08-17T13:42:41+00:00","insertUserID":164958,"insertUser":{"userID":164958,"name":"jtadhs","title":"Title","url":"https:\/\/community.smartsheet.com\/profile\/jtadhs","photoUrl":"https:\/\/lh3.googleusercontent.com\/a\/AAcHTtfNpbIYWnLk6ZczJ1ClRDc4ET2YJ_HxgNiq2jl7URt0RjU=s96-c","dateLastActive":"2023-08-16T23:05:43+00:00","banned":0,"punished":0,"private":false,"label":"✭"},"updateUserID":91566,"lastUserID":86866,"lastUser":{"userID":86866,"name":"Jeff Reisman","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Jeff%20Reisman","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/3V8W2AM105QE\/nIDXI4I7VDS7W.JPG","dateLastActive":"2023-08-22T19:45:13+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":7,"countViews":121,"score":null,"hot":3383993665,"url":"https:\/\/community.smartsheet.com\/discussion\/108829\/power-automate-question-multi-contact-list","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/108829\/power-automate-question-multi-contact-list","format":"Rich","lastPost":{"discussionID":108829,"commentID":391128,"name":"Re: Power automate question (multi-contact list)","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/391128#Comment_391128","dateInserted":"2023-08-17T13:42:41+00:00","insertUserID":86866,"insertUser":{"userID":86866,"name":"Jeff Reisman","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Jeff%20Reisman","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/3V8W2AM105QE\/nIDXI4I7VDS7W.JPG","dateLastActive":"2023-08-22T19:45:13+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"}},"breadcrumbs":[{"name":"Home","url":"https:\/\/community.smartsheet.com\/"},{"name":"Get Help","url":"https:\/\/community.smartsheet.com\/categories\/get-help"},{"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers"}],"groupID":null,"statusID":3,"attributes":{"question":{"status":"accepted","dateAccepted":"2023-08-15T22:16:09+00:00","dateAnswered":"2023-08-15T13:47:37+00:00","acceptedAnswers":[{"commentID":390662,"body":"
\n \n https:\/\/community.smartsheet.com\/discussion\/comment\/390588#Comment_390588\n <\/a>\n<\/div>\n

Is your Multi contact list column restricted to only values that are in the contact list for the sheet? If so, you might want to turn that off.<\/p>

Also make sure the column isn't locked.<\/p>

Also add a \"level\" parameter to the API call with value of 2, that should enable multi picklist and multi-contact list functions.<\/p>"}]}},"status":{"statusID":3,"name":"Accepted","state":"closed","recordType":"discussion","recordSubType":"question"},"bookmarked":false,"unread":false,"category":{"categoryID":320,"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers","allowedDiscussionTypes":[]},"reactions":[{"tagID":3,"urlcode":"Promote","name":"Promote","class":"Positive","hasReacted":false,"reactionValue":5,"count":0},{"tagID":5,"urlcode":"Insightful","name":"Insightful","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":11,"urlcode":"Up","name":"Vote Up","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":13,"urlcode":"Awesome","name":"Awesome","class":"Positive","hasReacted":false,"reactionValue":1,"count":0}],"tags":[]},{"discussionID":108731,"type":"question","name":"API export to excel to include the rowpermalink","excerpt":"trying to include the rowpermalink in my sheet export according to the API doc the ?include=rowpermalink in the URL should do it however it does not show in the row with all the other data from the sheet. any help would be greatly apprecitated. $URL =…","snippet":"trying to include the rowpermalink in my sheet export according to the API doc the ?include=rowpermalink in the URL should do it however it does not show in the row with all the…","categoryID":320,"dateInserted":"2023-08-09T14:56:39+00:00","dateUpdated":null,"dateLastComment":"2023-08-11T17:42:09+00:00","insertUserID":164847,"insertUser":{"userID":164847,"name":"palefty","url":"https:\/\/community.smartsheet.com\/profile\/palefty","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-08-11T17:41:17+00:00","banned":0,"punished":0,"private":false,"label":"✭"},"updateUserID":null,"lastUserID":164847,"lastUser":{"userID":164847,"name":"palefty","url":"https:\/\/community.smartsheet.com\/profile\/palefty","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-08-11T17:41:17+00:00","banned":0,"punished":0,"private":false,"label":"✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":2,"countViews":97,"score":null,"hot":3383369928,"url":"https:\/\/community.smartsheet.com\/discussion\/108731\/api-export-to-excel-to-include-the-rowpermalink","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/108731\/api-export-to-excel-to-include-the-rowpermalink","format":"Rich","tagIDs":[227],"lastPost":{"discussionID":108731,"commentID":390267,"name":"Re: API export to excel to include the rowpermalink","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/390267#Comment_390267","dateInserted":"2023-08-11T17:42:09+00:00","insertUserID":164847,"insertUser":{"userID":164847,"name":"palefty","url":"https:\/\/community.smartsheet.com\/profile\/palefty","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-08-11T17:41:17+00:00","banned":0,"punished":0,"private":false,"label":"✭"}},"breadcrumbs":[{"name":"Home","url":"https:\/\/community.smartsheet.com\/"},{"name":"Get Help","url":"https:\/\/community.smartsheet.com\/categories\/get-help"},{"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers"}],"groupID":null,"statusID":3,"attributes":{"question":{"status":"accepted","dateAccepted":"2023-08-11T17:42:18+00:00","dateAnswered":"2023-08-10T03:06:28+00:00","acceptedAnswers":[{"commentID":389950,"body":"

Hi @palefty<\/a> <\/p>

The Smartsheet API does not possess a native method to directly fetch or incorporate clickable row permalinks when you export a sheet to an Excel file. So, users need more intuitive, clickable links within their exported Excel sheets.<\/p>

To address this, I have implemented a workaround:<\/p>

(I used Smartsheet SDK to implement the workaround)<\/p>

\n \n https:\/\/gist.github.com\/jmyzk\/5cc4dfbbf79b010d374f0b5ad3fa0a4b\n <\/a>\n<\/div>


<\/p>

Fetching Permalinks:<\/strong> The code interacts with the Smartsheet API to retrieve each row's permalink values.<\/p>

Incorporating into the sheet:<\/strong> These permalink values are then populated into a designated column. When you export the sheet as an Excel file, you'll notice a column filled with URLs corresponding to the permalinks for each row in Smartsheet.<\/p>

\n
\n \n \"export<\/img><\/a>\n <\/div>\n<\/div>\n
\n \n https:\/\/app.smartsheet.com\/b\/publish?EQBCT=adda95b9ed0d49f192faa76e1535bc47\n <\/a>\n<\/div>

Making the Links Clickable:<\/strong> As a final step, to enhance user experience and ease of access, the code processes the Excel file to convert these plain URL texts into clickable hyperlinks. Thus, when users click these links in the Excel sheet, they're directed to the appropriate Smartsheet row online.<\/p>

With the implemented code, users can easily navigate to Smartsheet rows directly from their Excel sheets.<\/p>

\n
\n \n \"expoerted<\/img><\/a>\n <\/div>\n<\/div>\n


<\/p>"}]}},"status":{"statusID":3,"name":"Accepted","state":"closed","recordType":"discussion","recordSubType":"question"},"bookmarked":false,"unread":false,"category":{"categoryID":320,"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers","allowedDiscussionTypes":[]},"reactions":[{"tagID":3,"urlcode":"Promote","name":"Promote","class":"Positive","hasReacted":false,"reactionValue":5,"count":0},{"tagID":5,"urlcode":"Insightful","name":"Insightful","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":11,"urlcode":"Up","name":"Vote Up","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":13,"urlcode":"Awesome","name":"Awesome","class":"Positive","hasReacted":false,"reactionValue":1,"count":0}],"tags":[{"tagID":227,"urlcode":"api-and-developers","name":"API and Developers"}]}],"initialPaging":{"nextURL":"https:\/\/community.smartsheet.com\/api\/v2\/discussions?page=2&categoryID=320&includeChildCategories=1&type%5B0%5D=Question&excludeHiddenCategories=1&sort=-hot&limit=3&expand%5B0%5D=all&expand%5B1%5D=-body&expand%5B2%5D=insertUser&expand%5B3%5D=lastUser&status=accepted","prevURL":null,"currentPage":1,"total":213,"limit":3},"title":"Trending in API & Developers","subtitle":null,"description":null,"noCheckboxes":true,"containerOptions":[],"discussionOptions":[]}">

Trending in API & Developers