I am trying to set value of the connection field in a dropdown which is mapped with Account Name in the following function in javascipt. But it does not work. Am I doing something wrong?
function setAccountDropDown(accountRecordValue)
{
const dropdown = $('.t-form-connection select.select2-hidden-accessible');
const valueToSet = accountRecordValue;
// Check if the select2 instance exists
if (dropdown.hasClass('select2-hidden-accessible')) {
// Set the value and trigger the change event
dropdown.val(valueToSet).trigger('change');
console.log('Value set successfully:', valueToSet);
} else {
console.error('The dropdown is not initialized as a select2 component.');
}
No, I have not been able to make it work that way.
The workaround I use is a two-step form. I add the connection field that I want to set in the first step of the form and hide that field on the form, then make a rule to set the connection field, and then change the submit rules to go to step two of the form.
Typically, I won’t add any other fields to the first step and just rename the button to something like “Create new Invoice” or “Start Quote” so that it doesn’t seem like a two-step form.
replace the component Id with the id of the component containing the connection field and replace the your_field text with the field id of the connection field.