Data Import Custom Field code not working as expected

I have a Jira field that allows multi select values to be selected from a drop down. I created a new custom field in the Data Import set-up, under Custom Fields. The intent is to return the word “Multiple” when more than one value exists and just return the value when only one value exists. This is done by checking if a comma exists in the value, as values are separated by commas.

The custom field correctly returns the single value, but it is not returning ‘Multiple’ for multiple values…it still returns the multiple values that are in the field.

Here is the syntax used:

// Check if LOB field is not empty and if it includes a comma (,)
if (issue.fields.customfield_15600 && issue.fields.customfield_15600.includes(“,”))
{return “Multiple”;
} else {
// Return the actual field value if no comma
return issue.fields.customfield_15600;
}
// Return undefined if field is empty
return undefined;

Here are example field values in the new custom LOB field:

The second on the list should be “Multiple”.

Can you please help me understand what I am missing in making this work correctly?

Check instead of “includes” function with this:

if (issue.fields.customfield_15600 && issue.fields.customfield_15600.indexOf(",") > -1)

If not, that is because your Custom Field is an array. Therefore, you have to use the length function
issue.fields.customfield_15600.length > 1

Then, you can test it with any of your tickets

1 Like

Thank you so much for the suggestion. I have tried this solution but still get the same results.

// Check if LOB field is not empty and if it includes a comma (,)
if (issue.fields.customfield_15600 && issue.fields.customfield_15600.indexOf(“,”) > -1)
{return “Multiple”;
} else {
// Return the actual field value if no comma
return issue.fields.customfield_15600;
}
// Return undefined if field is empty
return undefined;

Not getting the word “Multiple” back; still getting the field values:

Any other thoughts??

Ok, I tried it with your other suggestion and it is working great now. Thank you for your help!

// Check if LOB field is not empty and if it includes a comma (,)
if (issue.fields.customfield_15600 && issue.fields.customfield_15600.length > 1)
{return “Multiple”;
} else {
// Return the actual field value if no comma
return issue.fields.customfield_15600;
}
// Return undefined if field is empty
return undefined;

2 Likes