The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Database picker field showing '- null' at the end of drop down selection

Jose Ramirez
Contributor
December 12, 2024

We implemented a database picker field that almost works the way we need it to, however, during the drop down selection, we are seeing a '- null' in the UI from our field, only when selecting the value.

When the value is selected, the trailing '- null' goes away (that is good) in the actual issue field (view screen).

In the drop down, the value '- null' does not appear.DBFieldPic1.pngDBFieldPic2.pngDBFieldPic3.png

Only in the field itself during edit, does the '- null' appear.

I have pictures included above for a better illustration.

//Configuration Script below

 

import com.atlassian.jira.issue.Issue
import com.onresolve.scriptrunner.canned.jira.fields.editable.database.SqlWithParameters
import groovy.sql.GroovyRowResult


// IS_ACTIVE = 1 Active/Enabled

getSearchSql = { String inputValue, Issue issue, originalValue ->
    // return SqlWithParameters, that will control the search SQL..., eg:
    new SqlWithParameters("""
        select INITIATIVE_INTERNAL_ID, INITIATIVE_ID, INITIATIVE_NAME, IS_ACTIVE
        from [rpt].[JIRA_INITIATIVE_V]
        where lower(INITIATIVE_NAME) like '%' + lower(?) + '%' and
        (IS_ACTIVE = 1 or INITIATIVE_INTERNAL_ID = ?)
        """, [inputValue, originalValue])
}

getValidationSql = { id, Issue issue, originalValue ->
    new SqlWithParameters("""
        select INITIATIVE_INTERNAL_ID, INITIATIVE_ID, INITIATIVE_NAME,IS_ACTIVE
        from [rpt].[JIRA_INITIATIVE_V]
        where INITIATIVE_INTERNAL_ID = ? and
        (IS_ACTIVE = 1 or ? = ?)
        """, [id, id, originalValue])
}

//renderOptionHtml = { String displayValue, GroovyRowResult row ->
//    "${row.INITIATIVE_ID} - ${row.INITIATIVE_NAME}"
//}

renderOptionHtml = { String displayValue, GroovyRowResult row ->
    def init_id = row[1].toString()
    def init_name = row[2].toString()
    "$init_id - $init_name"
}




1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
Tuncay Senturk _Snapbytes_
Community Champion
December 13, 2024

Hi @Jose Ramirez 

I am not sure but this may be most probably because how you handle empty or null values for the INITIATIVE_NAME field. When it is null or empty, the rendered string becomes something like INITIATIVE_ID - null.

I'd change the renderOptionHtml function as below

renderOptionHtml = { String displayValue, GroovyRowResult row ->
def init_id = row[1]?.toString() ?: ""
def init_name = row[2]?.toString() ?: "No Name"
"$init_id - $init_name"
}

 

Jose Ramirez
Contributor
December 17, 2024

Hi @Tuncay Senturk _Snapbytes_ ,

Your answer was InitCDB.pngcloser to the solution, but the No Name appended the '- No Name' to the value, therefore I took the extra step and removed the "No Name" to it, made it "", and we're even closer now, still have a trailing '-' (see picture).

 

renderOptionHtml = { String displayValue, GroovyRowResult row ->
   def init_id = row[1]?.toString() ?: ""
   def init_name = row[2]?.toString() ?: ""
   "$init_id - $init_name"
}
This is passable for our purposes but it would be perfect to get the trailing '-' out of it.
Jose Ramirez
Contributor
December 17, 2024

@Tuncay Senturk _Snapbytes_  Thank you for getting us closer to our goal.

Tuncay Senturk _Snapbytes_
Community Champion
December 18, 2024

Use the below code

renderOptionHtml = { String displayValue, GroovyRowResult row ->
def init_id = row[1]?.toString() ?: ""
def init_name = row[2]?.toString() ?: ""

// Construct the display value based on available parts
if (init_id && init_name) {
"$init_id - $init_name"
} else {
"$init_id$init_name"
}
}

 

Jose Ramirez
Contributor
December 18, 2024

Awesome, thank you, that was the golden touch.

Tuncay Senturk _Snapbytes_
Community Champion
December 18, 2024

Pleasure!

Tuncay Senturk _Snapbytes_
Community Champion
December 18, 2024

Please accept the answer so that others can benefit from it.

DEPLOYMENT TYPE
SERVER
VERSION
9.12.14
TAGS
AUG Leaders

Atlassian Community Events