0

I'm writing a tampermonkey script to automatically populate a field. It's a incident management site, so there are fields like group, summary, etc. The field I want to change has this ID: called sys_display.incident.assigned_to, and I can change it's value with the default document.getElementById(assignedTo).value = "someone". But since it's an autocomplete field, whenever I change it through JS it doesn't seem to trigger the AJAX autocomplete itself, since it validates this and populates other fields with this information.

The element is as follows:

<input id="sys_display.incident.assigned_to" name="sys_display.incident.assigned_to" aria-labelledby="label.incident.assigned_to" type="text" autocomplete="off" autocorrect="off" value="Gabriel Bocon" ac_columns="email" ac_order_by="name" data-type="ac_reference_input" data-completer="AJAXTableCompleter" data-dependent="assignment_group" data-ref-qual="" data-ref="incident.assigned_to" data-ref-key="null" data-ref-dynamic="false" data-name="assigned_to" data-table="sys_user" class="form-control element_reference_input" style="; width:160px" spellcheck="false" onfocus="if (!this.ac) addLoadEvent(function() {var e = gel('sys_display.incident.assigned_to'); if (!e.ac) new AJAXTableCompleter(gel('sys_display.incident.assigned_to'), 'incident.assigned_to', 'assignment_group', ''); e.ac.onFocus();})" aria-required="true" tabindex="-1">

When I click on it (focus), it triggers the autocomplete and updates the DOM which receives the following attributes:

role="combobox" aria-autocomplete="list" aria-owns="AC.incident.assigned_to" aria-activedescendant=""

And my current script snippet is this:

setTimeout(function(){

        var analyst = GM_getValue('analyst');
        var assignedTo = document.getElementById("sys_display.incident.assigned_to");

        assignedTo.setAttribute("tabindex", "-1");

        setTimeout(function() {
            assignedTo.value = analyst;
        }, 1000);

}

I set a timeout so that the page fully loads, even though the script is set to run at idle only. I even set a tabindex to it so I could tab in and out of it, to no avail. I tried using jQuery to trigger it, which also didn't work.

I'm no expert, but I'm stuck, any help is greatly appreciated.

1 Answers1

0

I am sorry, it seems that I wasn't able to focus on the element because I was keeping the DEV console open, as already answered here: https://stackoverflow.com/a/15859155/8633664