javascriptretool

Retool JavaScript Transformer Error - "expected an identifier and instead saw switch"


I have been playing around with retool to make a CRM dashboard, and am trying to figure out why I am getting this syntax error in my JavaScript Transformer. I am using Stripe's API to issue a refund and am using the JavaScript transformer to give the user a notification based on their reason for returning a product. The main error I am getting is on switch, which says "expected an identifier and instead saw switch". The others say there is a missing } or semicolon.

let orderId = {{table4.selectedRow.data.orderId}}
let refundAmount = {{numberInput3.value}}

let openingBlurb = 
  switch({{select1.value}}) {
    case: 'toolate':
    openingBlurb = 'I am so sorry about your order being late! I went ahead and refunded ' + refundAmount + ' to your card. '
  break
  case: 'didntlike':
    openingBlurb = 'I am so sorry you did not like your order!'
    break
    case: 'cancel':
    openingBlurb = 'I have cancelled your order!'
  }

enter image description here

I do not typically code in JS so I am hoping it is just some bad syntax. Thank you!


Solution

  • Change line number 4 to let openingBlurb; This will ensure that the scope of the variable is not limited to the switch, and you will be able to do what you want with it outside. It is failing right now because you have a "=" sign and you haven't assigned anything to it after the "=", so it expects an identifier.