Pre-fill a connection field on a form with javascript

@Chem, I’m looking at you for this one!

I’m trying to pre-select the connection field on a details page, there is a very specific reason I’m doing this which is difficult to explain quickly. If I use the console I can do it with this javascript code:

document.querySelector("#select2-xfyl-container").innerHTML = “AMEC Place-782.01-2020”;

The problem is, that ID is dynamic and changes every time the page loads. My question is Chem, is this possible to do with some other method? by class maybe?

Here is the select box code screenshot where I get the ID from

Referencing this topic, if the Get Value from URL were to be updated to include connection fields, would that be helpful?

Get value from URL

Maybe, depends if the record ID would work when inserted in the connection field. I’ll test that right now in the console.

Just tested it and the record id does work when submitted, I believe that functionality would work if it were availible soon…Do you know something I don’t @tim.young?

Lol no, unfortunately not. Do me a favor and post it in #suggestion-box?

I know this is an old thread, but hoping to get a resolution to this question. Like the OP I’d want to pre-fill a connection field inside a form using javascript to inject a logged in user value. I’ve worked out how to get the element ID when the page loads, but haven’t been able to figure out the correct method to actually select the connection I want
Hoping @Chem can help with the rest of the solution.