Dynamically select options field

Hi All,
Unable to load dynamically load select vaule from DB to assignee field:

Here is js file:

frappe.ui.form.on('Hardware Case', {
        vendor(frm) {
                let vendor = frm.doc.vendor
                console.log(frm)
                if (vendor){
                   frappe.call({
                  method: "spms.hardware_management_system.doctype.hardware_case.hardware_case.get_assignee_by_vendor",
                  args: {
                 vendor: vendor },
           }).done((r) =>{
              if (!r.exc) {
            // code snippet
               console.log(r)
               let options = [];
              for (i = 0; i < r.message.length; i++) {
                options[i]= r.message[i][0];
                } 
               cur_frm.set_df_property('assignee', 'options', options);
               cur_frm.refresh_field('assignee');
             }
           })
         }

        }
})

Back end Python code:

import frappe
from frappe.model.document import Document

class HardwareCase(Document):
        pass

@frappe.whitelist()
def get_assignee_by_vendor(vendor):
    return frappe.db.sql(f"""select first_name from tabvendor_employee where vendor_name={vendor}""",as_dict=False)

But getting below error when trying to select value:

Capture

Please help.

Hi,
use \” around the {vendor}.
Jirka

Not clear. Please specify more.

I’ve modified a little, but still getting error:
JS file:

frappe.ui.form.on('Hardware Case', {
        vendor(frm) {
                let vendor = frm.doc.vendor
                console.log(frm)
                if (vendor){
                   frappe.call({
                  method: "spms.hardware_management_system.doctype.hardware_case.hardware_case.get_assignee_by_vendor",
                  args: {
                 vendor: vendor },
           }).done((r) =>{
              if (!r.exc) {
            // code snippet
               console.log(r)
               let options = [];
              for (i = 0; i < r.message.length; i++) {
                options[i]= r.message[i][0];
                }
               console.log(options)
               set_field_options("assignee", options)
               //cur_frm.set_df_property('assignee', 'options', options);
               //cur_frm.refresh_field('assignee');
             }
           })
         }

        }
})

assignee is the select field.

Still getting error.
Can you give a select field, which populates from database?

Regards.

If the frm.doc.vendor is “just” a string value, than try:

frappe.db.sql(f'''select first_name from tabvendor_employee where vendor_name="{vendor}"''',as_dict=False)

To Option into Select Field you should pass string: “Md.Faisal\nNathan”

Here is example from browser console:

Hi @Narayan_Banik ,
now I see from your another posts that you are looking for set_query on the “link” field.
The link field has a “linked” Doctype in the option and set_query filters the results from linked Doctype list.

The upper my answer is applied just for “select” field where in the option you can find a string with selections.

I hope it is clear :wink:
Jirka