Why is my Connect field not live?


Symptoms

When a change is made in the datasource, it's not automatically reflected in the Connect field.


Example

Let's take the example of the following SQL table:

user_iduser_firstnameuser_lastname
1SimonLaffont
2NapoléonBonaparte
3GengisKhan
4FrédéricBarberousse

Let's say we want to display the user firstname. So here is the Connect field configuration we have set up:

When we populate this Connect field in an issue, everything works fine:


But as soon as we change this value in the datasource, this modification is not reflected in the Connect field:



Cause

This problem occurs because a Connect field key has been changed:

It is important to know that the key is used to set the link between the datasource and the Connect field. When it's changed, the Connect field key is no longer relevant and the Connect field can no longer retrieve the corresponding value from the datasource.



Resolution

1. Change the Connect field key

To solve this problem, you have to change the key and choose another column that never changes. In our case, the user_id column is the most appropriate so we update our Connect field accordingly:

2. Update the relevant issues

As your key has been changed, all issues in which the Connect field already contains a value must be updated because this value corresponds to the old key which is no longer relevant. To do this, you need to edit your Connect field query and write a temporary query using $currentCustomfieldValue. This variable is used to retrieve the currently selected value stored in Jira. 
In our case, the old key was user_firstname so here is the temporary query we need to write: 

Then, the Connect field must be updated using one of the methods described in the following documentation: How to set Elements Connect field on existing issues?

(warning) Be very careful: if no temporary query has been written to retrieve the value currently stored in Jira (using $currentCustomfieldValue), updating the Connect field will automatically select the first value returned by the query and cause a data loss. If you are not sure how to write this request, please contact our Support team.

(info) If it's a multiple value field, then you need to adapt the temporary query accordingly and use the stringList() or serialize() functions to retrieve all the values contained in $currentCustomfieldValue (for further information, see Velocity). In our case, the query would be:

SELECT user_id, user_firstname FROM user
WHERE user_firstname IN ($currentCustomfieldValue.stringList())

Once the Connect field has been updated in all relevant tickets, then restore the query to its original state:

(info) Please see also How to handle updated or deleted values in the datasource?