hqDefine('locations/js/utils', [
    'jquery',
    'hqwebapp/js/initial_page_data',
    'select2/dist/js/select2.full.min',
], function (
    $,
    initialPageData
) {
    var show_inactive, location_search_url, locs;

    var enableLocationSearchSelect = function () {
        $('#location_search_select').select2({
            ajax: {
                url: location_search_url,
                dataType: 'json',
                data: function (params) {
                    return {
                        q: params.term,
                        page_limit: 10,
                        page: params.page,
                        show_inactive: show_inactive,
                    };
                },
                processResults: function (data, params) {
                    var more = data.more || (params.page * 10) < data.total;
                    return { results: data.results, more: more };
                },
            },
        });
    };

    var reloadLocationSearchSelect = function () {
        $('#location_search_select').select2('val', null);
        enableLocationSearchSelect();
    };

    var clearLocationSelection = function (tree_model) {
        reloadLocationSearchSelect();
        tree_model.load(locs);
    };

    $(function () {
        show_inactive = initialPageData.get('show_inactive');
        location_search_url = initialPageData.reverse('location_search');
        locs = initialPageData.get('locations');
    });

    return {
        enableLocationSearchSelect: enableLocationSearchSelect,
        reloadLocationSearchSelect: reloadLocationSearchSelect,
        clearLocationSelection: clearLocationSelection,
    };
});

@@ -263,32 +263,46 @@
 ion () %7B%0A       
+ var $select =
  $('#location_se
@@ -306,32 +306,49 @@
 _search_select')
+;%0A        $select
 .select2(%7B%0A     
@@ -975,16 +975,498 @@
     %7D);%0A
+        var initialValue = initialPageData.get('locationSearchSelectInitialValue');%0A        if (initialValue) %7B%0A            // https://select2.org/programmatic-control/add-select-clear-items#preselecting-options-in-an-remotely-sourced-ajax-select2%0A            var option = new Option(initialValue.text, initialValue.id, true, true);%0A            $select.append(option).trigger('change');%0A            $select.trigger(%7Btype: 'select2:select', params: %7Bdata: initialValue%7D%7D);%0A        %7D%0A
     %7D;%0A%0A

update location util to accept initial value