Try ERPNext Buy Support Partners Foundation

Custom script for getting field value from database table

Hello guys.
i am trying to fetch value of “qty_after_transaction” from “tabStock Ledger Entry” table in custom script. But is there any possibility to get that value with the help of custom script. Because i searched andf found following method
frappe.db.get_single_value(doctype, field)
in which it is clearly mentioned that i should pass doctype name as parameter and there is no doctype named “Stock Ledger Entry”. Stock Ledger Entry is actually form.

frappe.ui.form.on(‘Batch’, {
refresh(frm) {
// your code here
var stockQty=frappe.db.get_single_value(“Stock Ledger Entry”, “qty_after_transaction”)
//var a=21;

	frm.set_value("batch_stock", stockQty);



1 Like{
        async: false,
        method: "frappe.client.get_value",
        args: {
            "doctype": "Material Request Item",
            "filters": {
                'name': material_request_item_name // where Clause 
            "fieldname": ['qty', 'ordered_qty'] // fieldname to be fetched
        callback: function (res) {
            if (res.message != undefined) {

1 Like

i tried but no luck got error…can you clarify me that. Can we fetch value of fields from Forms(not doctype)?
My scenario is:
i have to fetch the “Actual qty” from “stock ledger entry” (that is not a doctype) to batch doctype, and set that value in the field inside the same doctype called batch.{
    method: 'frappe.client.get_value',
    args: {
        'doctype': 'Item',
        'filters': {'name': item_code},
        'fieldname': [
    callback: function(r) {
        if (!r.exc) {
            // code snippet

Try this ajax call method change the parameters depending upon your requerments

How to use the fetched value?

@raheeb which value you want to fetch and from where you want to fetch the value from the database or form itself.

I want to fetch a value from the database using certain conditions and put it in a field.
I have a field “A” in Customer. After performing query with conditions on the database I get a value. How do I insert that value achieved from the query into the field “A”.

how i can put those fetched args into my form ?

how to use fetcged value ?