Issue generic get field?

I’m playing with ScriptRunner’s dynamic forms feature (https://scriptrunner.adaptavist.com/latest/jira/dynamic-forms.html). It has a FieldPicker option, which returns a Field object (system or custom).

But how do I retrieve field value in a generic way?

The Issue interface (Issue (Atlassian JIRA - Server 8.1.0 API)) doesn’t seem to have any methods that take a Field, only CustomField. For system fields it seems to be missing a generic getFieldValue(Field f) or getFieldValue(String fieldName)… I have to use the specific method for each one instead like getSummary() and getPriority().

Is there a way to make use of a Field object to get its value?

Field class has a .getProperties() method. Among the properties, “jsonSchema” will give you a JsonType object.

Using JsonType methods .getType() and .getCustom(), I am able to tell what data type the field is (including Insight fields).

There’s no solution to a generic setFieldValue() method though, but at least there aren’t a lot of system field setters, so I just switch on the field name and call each specific method.