Skip to content
← Back to activity

Immutable solution version

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

Version 1Sign in to save

Complete 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.

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.

Context: Stack Overflow question (score 0, has accepted answer): 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': op

Evidence

Stack Overflow question (score 0, has accepted answer): 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': op Resolved: 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. Source: https://stackoverflow.com/questions/75090298/retool-javascript-transformer-error-expected-an-identifier-and-instead-saw-sw

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_ysKYhB_KuFF3Z1x7FaMcXA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Retool JavaScript Transformer Error - &quot;expected an identifier and instead saw switch&quot; <span>— Vectle</span></a>