Jira Widget: Settings not persisting during reconfiguration

I’m building a custom widget for Jira that includes configuration settings. One setting uses a project/filter selector.

The issue happens when trying to reconfigure the widget settings. I looked at the timesince widget code for reference and found this part:

if (/^jql-/.test(widget.getPref("selectedProjectFilter"))){
    filterSelector = {
        userpref: "selectedProjectFilter",
        type: "hidden",
        value: gadgets.util.unescapeString(this.getPref("selectedProjectFilter"))
    };
} else {
    filterSelector = AJS.gadget.fields.projectOrFilterPicker(widget, "selectedProjectFilter", args.options);
}

I copied this approach from the timesince widget. However, even when the widget is already configured, the code always goes to the else branch.

I don’t have much experience with JQL syntax and the regex condition confuses me. Normally when I call the REST API to get config data:

widget.getPref("selectedProjectFilter")

This gives me a string with the selected project or filter ID.

How do I make my widget save and restore the previous configuration like other Jira widgets do?

The regex /^jql-/ checks if your preference starts with “jql-” - that’s how Jira marks saved filters vs project selections. Filters get the “jql-” prefix, projects don’t. Sounds like your preference isn’t saving in the right format during setup. First, check your widget descriptor XML - make sure the userpref for selectedProjectFilter has the correct type attribute. Also verify you’re calling gadgets.window.adjustHeight() after config changes. I’ve seen widgets fail to save settings without that call. The timesince widget works because it handles both cases properly. You’ll probably want to debug what format your preference is actually saving as first.

Same thing happened to me with a widget integration. The issue is usually how the preference gets set up during first config. When you configure it initially, the value might save as just the project or filter ID without the prefix your regex needs. I had to make sure the initial save formatted the preference right. Jira’s filter picker automatically adds the jql- prefix when you pick a saved filter, but project selections stay as plain IDs. If you’re always hitting the else branch, the preference is probably empty or formatted wrong. Check if widget.getPref("selectedProjectFilter") returns null or undefined when reconfiguring. Sometimes it doesn’t load properly during widget initialization. Adding a null check before your regex test might fix the persistence problem.

yea, i noticed that too! maybe your widget isn’t properly saving the preference. try logging the value from getPref just before your if condition, it might show if it’s being set right or not. we all mess with timing sometimes!