UpsertRow help - Can’t make it update

Can anyone assist me in figuring out the whole upsertRow() api call?

I’m using it successfully to add new rows, but just can’t quite get the syntax right to have it update existing rows no matter what I do.

But the way - I’m writing in JavaScript within google apps script.

Any small example code so I might better understand syntax is appreciated!!!

Sure, here’s some sample code I got working:

function upsertRows() {
  let docId = "<Doc ID>";
  let tableName = "Test";
  let request = {
    rows: [{
      cells: [{
        column: "Name",
        value: "Foo",
      },
      {
        column: "Num",
        value: Math.random(), // Random number.
      }]
    }],
    keyColumns: ["Name"],
  };
  CodaAPI.upsertRows(docId, tableName, request);
}

It assumes the doc has a table called “Test” with a “Name” and “Num” column. Hope this helps!

Ok - So then what is saying is that:

if - there is a value of “foo” in the column “name” already

  • then - update that row, specifically the Num column with a random number

else - create a new row with the corresponding values:

  • Name = Foo
  • Num = Random Number

Yes, that’s it exactly!

Thank you! And then last question - Let say it finds a row to update, but there is nothing to update in that row. . . Will it essentially re-write all the columns values, or just skip over it and move to the next row?

I just ran a simple test, and it appears that the row isn’t modified (thisRow.Modified() doesn’t change).

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.