Dynamic Selection Box

@vivek

frappe.ui.form.on('Sales Order', 'onload', function(frm){
    frappe.call({
         method: 'frappe.client.get_values'
         args: {
             'doctype': 'NFe Parameters', // DocType that is the source of the options
             'fields': ['key', 'value'], // Fields that will provide the options (one for value, another for label, or use a single one for both)
             'filters': [['NFe Parameters', 'group', '=', 'IPI CST']] // filter conditions while fetching a list of values
         },
         callback: function(res){  // receive the response from the server
             var options = [];
             (res.message || []).forEach(function(row){   // start a loop over all options in the response, or in a empty list; 
               options.push({'value': row.key, 'label': row.value}) // makes a option entry 'value' and 'label'
             });
             frm.fields_dict.ipi_cst.options = options; // define de options for the field in this case (ipi_cst)
         }
    });
});

@ruchin78

3 Likes