Help

Custom Code Help Updating Webflow CMS Item

1051 0
cancel
Showing results for 
Search instead for 
Did you mean: 
NoCodeLearner32
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi there!

I've written some code where I'm trying to cycle through separate columns and based on the values in the columns output a different color. Then I want to send that color information to webflow. I think I'm close but I'm getting an error and can't figure out what to do differently.

Here's the code: 

let table = base.getTable('Trust Fall Table');
let query = await table.selectRecordsAsync();
let records = query.records;


for (let record of records) {
  let field1 = record.getCellValue("INTEGRITY-Q1");
  let field2 = record.getCellValue("INTEGRITY-Q2");
  let field3 = record.getCellValue("INTEGRITY-Q3");
  // Repeat for all 20 fields...

  let color;

  if (field1 == 1 || field1 == 2 ||
      field2 == 1 || field2 == 2 ||
      field3 == 1 || field3 == 2 ||
      // Repeat for all 20 fields...
     ) {
    color = '#ffffff';
  } else if (field1 == 3 || field2 == 3 || field3 == 3 || /*...*/) {
    color = 'DB3F32';
  } else if (field1 == 4 || field1 == 5 ||
             field2 == 4 || field2 == 5 ||
             field3 == 4 || field3 == 5 ||
             // Repeat for all 20 fields...
            ) {
    color = 'F1EDE5';
  } else {
    color = null;
  }

  // Send color to Webflow API using PATCH method
  let url = 'https://api.webflow.com/collections/644947b59b863f673ea3c4d1/items/64494dfff401ee271ff0fe36';
  let headers = {
    'Authorization': 'HIDING MY API KEY HERE',
    'accept-version': '1.0.0',
    'content-type': 'application/json'
  };
  let data = {
    fields: {
      'Q1': color,
      'Q2': color,
      'Q3': color
    }
  };
  let response = await fetch(url, {
    method: 'PATCH',
    headers: headers,
    body: JSON.stringify(data)
  });
}

 

This is the error Im getting:

SyntaxError: Unexpected token ')'
    on line 1
    at s on line 1
    at Generator._invoke on line 1
    at Generator.next on line 1
    at t on line 1
    at a on line 1
    on line 1
    on line 1

 Any thoughts? 

-Nicholas

0 Replies 0