Execution of custom JavaScript code raised the following error: unterminated string literal

I’m getting this error when try to add a custom Javascript code:
Execution of custom JavaScript code raised the following error: unterminated string literal

the code that I’m using:

[jira.customfield_mpc_e]
name = "Epic MPC Type name" 
data_type = "string"
dimension = true
update_from_issue_key = "epic_key"
javascript_code = '''
if(issue.fields.customfield_17704 ) {
   issue.fields.customfield_mpc_e = issue.fields.customfield_17704;
}
'''```

I can't see the mistake

Hi @ivera,

The javascript_code should end with three apostrophes as it started, like this '''.
The given code example ends with 3 apostrophes and then there are added 3 extra unsupported characters ```. Delete the last 3 and the code should work correctly.

Best,
Zane / Support@eazyBI.com

Those apostropes were added when I made the comment.
Anyway I tried this code I failed as well

In import options, field “Custom JavaScript code”, you should paste in only the javascript_code part without other properties of advanced settings and with out opening/closing apostrophes enclosing the code (see picture below)

Please see this section on how to validate the Javascript calculated custom fields: JavaScript calculated custom fields

Best,
Zane / support@eazyBI.com

It works!! thank you so much.
Last question (I promise): Where should I see the new button? as a dimension?

  1. When you have tested the javaScript code in import options, you can clear it from there.
    The code validation is done.

  2. Got to eazyBI advanced settings (eazyBI >> System administration >> Settings >> tab Advanced settings) and paste the settings with dimension name, data type, and javascript code there (Advanced settings for custom fields).

    [jira.customfield_mpc_e]
    name = "Epic MPC Type name" 
    data_type = "string"
    dimension = true
    update_from_issue_key = "epic_key"
    javascript_code = '''
    if(issue.fields.customfield_17704 ) {
       issue.fields.customfield_mpc_e = issue.fields.customfield_17704;
    }
    '''
    

    Save the settings.

  3. Then go back to import options, tab Custom fields, the new custom field “Epic MPC Type name.”
    should be there. Select it for data import as property and dimension and Import data (Jira custom fields).

Thanks. It works now!

1 Like

Sorry for bothering you Zane, but it’s not retrieving information from the epic custom field

the epic from those issues has a custom field called MPC type and the field is set

@ivera, you might want to check how the custom field “MPC Type” is stored for epic issues in JSON format and whether it is visible in eazyBI. And adjust the settings accordingly.

  1. In Jira, find one epic that has value for “MPC Type.”
  2. Go back to eazyBI import options, tab “Additional options”, and validate what information you can see about this epic. Enter only the epic issue key in “Test custom javaScript code with the issue” and leave the “Custom JavaScript code” field empty.
  3. Check how the customfield_17704 look in the JSON format. Is value available? Does the field have several parameters like id, name and value?

Hi Zane! You were right, I’m not receiving the customfield_17704 in EazyBI. Something weird is that customfield_17900 is also a select list field and has a value as 17704.

There is something that I can do to bring that field to eazybi?

@ivera, eazyBI does not receive data of the customfield_17704 and therefore its value is not inherited also for epic child issues. It might be that this custom field has a data type that is not recognized by eazyBI and therefore it is not received.

You may enable such custom fields by defining a data type for the cutom field in eazyBI advanced settings. If a custom field contains a textual value, the settings might look like this:

[jira.customfield_17704]
data_type = "string"
dimension = true

Here are more details on custom field data import: Advanced settings for custom fields.

Thanks!! It worked.
I was not importing both fields. Now that I am it’s working!

Thanks for your time!

1 Like

I have tested the code for pulling the last comment date and it worked just fine, but when I tried to add it as a custom field through Advanced Settings, there are two persistent errors: Missing “return” and then Execution of custom JavaScript code raised the following error: unterminated string literal. Even though my testing is working correctly, it is still having the same problem over and over again.

image

Hi @Luiz_Guerra

Please use # before comments instead of // in the Advanced settings.

Best regards,
Nauris


i din’t mention eny comment but also its throwing an missing return error

Hi @Yashwanthkumar_Shiva

If you are defining a new calculated field in the import options, then the settings should be filled out as follows:

The result must be returned with the “return” statement:

if (issue.fields.comment && issue.fields.comment.comments) {
  return issue.fields.comment.comments.length;
}

Best regards,
Nauris

Got it thank you @nauris.malitis it was helpfull


In the advance setting testing its showing the comments but in the report its showing empty

Hi @Yashwanthkumar_Shiva

If you wish to return the last comment, the 3rd line should be returning the “body” value that you saved in the 2nd line:

if (issue.fields.comment && issue.fields.comment.comments && issue.fields.comment.comments.length > 0)  {
  var lastcomment = issue.fields.comment.comments[issue.fields.comment.comments.length-1];
  return lastcomment.body;
}