1

Hi I am retrieving some values from database in onReady function of JS it gives me error Uncaught SyntaxError: Invalid or unexpected token

Below is my onReady function

var clientId = getFieldValue('editForm:clientId');
               if (!clientId) {
                   if ('#{applicationObject.attributes['isProduction']}' == true || '#{applicationObject.attributes['isProduction']}'=='true') {
                       clientId = '#{applicationObject.attributes['productionClientId']}';
                   } else {
                       clientId = '#{applicationObject.attributes['nonProductionClientId']}';
                   }
               }

   Ext.getDom('editForm:clientId').value = clientId;

The expected value of clientId is

1:ACP:cSHnNw4v7MhdAGuQ1QF0PnuVOh1PFVBz0u2hlzx81uMR7GJMUBGe08XIKmb/SE7WvMpeprAPPSQw gQd+N+fOdA==

In Chrome debugger it shows as below

enter image description here

Prasad Parab
  • 437
  • 1
  • 7
  • 26

1 Answers1

1

Since you are inserting a multi-line string the easiest here (if you cannot modify that string or do not want to split it and then concatenate using 'line1' + 'line2') is to use so called template literals as they support multi-lines. Please also have a look at this question as it's not supported everywhere.

Tomasz Poradowski
  • 1,251
  • 11
  • 12
  • Unfortunately I do not have Control over the string as it is directly retrieved from a JSON object(applicationObject) and the JSON object is created at backend based on user information in database. – Prasad Parab Feb 16 '20 at 15:41
  • 1
    But have you tried to use backticks instead of single quotes in line `'#{applicationObject.attributes['productionClientId']}'`? – Tomasz Poradowski Feb 16 '20 at 19:17
  • Thanks, It's work with backticks ☺️ Just for my knowledge What is difference in single qoute and backticks? – Prasad Parab Feb 17 '20 at 07:21
  • 1
    I included the link to description of [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) in my answer already - you can find all the interesting details there. – Tomasz Poradowski Feb 17 '20 at 11:19