I have a ScriptRunner field for the Last Comment which includes the date and time at the start. I would like to split out the Date and Time only from this for use in eazyBI to see when the last comment was added.
I tried the following in the Advanced setting but I get an error: SyntaxError: missing ; before statement
[jira.customfield_LastCommentDate]
# Gets date from Last Comment field
name = "Last Comment Date"
data_type = "string"
javascript_code = '''
if (issue.fields.customfield_10333)
{
var str = issue.fields.customfield_10333.value;
var index = str.indexOf( " ", str.indexOf( " " ) + 1 );
var issue.fields.customfield_LastCommentDate = index >= 0 ? str.substr( 0, index ) : str.substr( index + 1 );
}
'''
1 Like
Hi Rob!
The SyntaxError comes from the last line where you are defining a new variable for the issue.fields … Issue is an existing object and defining it causes the problem. Try the following
[jira.customfield_LastCommentDate]
# Gets date from Last Comment field
name = "Last Comment Date"
data_type = "string"
javascript_code = '''
if (issue.fields.customfield_10333)
{
var str = issue.fields.customfield_10333.value;
var index = str.indexOf( " ", str.indexOf( " " ) + 1 );
issue.fields.customfield_LastCommentDate = index >= 0 ? str.substr( 0, index ) : str.substr( index + 1 );
}
'''
Lauma / support@eazybi.com
Thank you @lauma.cirule. It no longer errors but I must have a problem with my javascript as the field value is as shown on the right with one space after the Date and one space after the time but it returns blank.
Hi @robaduncan!
I was not able to reproduce the problem, the Javascript seems to work as expected.
Note that you can test it within the import screen for particular Issue.
Lauma / support@eazybi.com