Hi everyone,
I am trying to link a field in Jira to SQL database. I would like to filter the values based on another field called "Location". The script works fine during initial selection but the list can not be modified afterwards so if the user had forgot to add an asset they have to delete all previously selected assets and re-enter them. I am not sure how I can use original values to be passed in new search query. Here is my code that works initially but throws error after updating:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.Option
import com.onresolve.scriptrunner.canned.jira.fields.editable.database.SqlWithParameters
def customFieldManager = ComponentAccessor.customFieldManager
getSearchSql = { String inputValue, Issue issue, String originalValue ->
def customField = customFieldManager.getCustomFieldObjects(issue).findByName('Location')
def Lab_Location = issue.getCustomFieldValue(customField) as Option
new SqlWithParameters(
"select ID, Local_Name, Lab_Location from assets where lower(Local_Name) like concat('%', lower(?), '%') and Lab_Location = ?",
[inputValue, Lab_Location?.value]
)
}
getValidationSql = { String id, Issue issue, String originalValue ->
def customField = customFieldManager.getCustomFieldObjects(issue).findByName('Location')
def Lab_Location = issue.getCustomFieldValue(customField) as Option
new SqlWithParameters("select ID, Local_Name, Lab_Location from assets where ID = CAST(? AS SIGNED) and Lab_Location = ?", [id, Lab_Location?.value])
}