Server Calls (AJAX)

dontmanage.call

dontmanage.call(method, args)

Makes an AJAX request to the server, where the method which is the dotted path to a whitelisted Python method, is executed and it's return value is sent as the response.

// call with no parameters
dontmanage.call('ping')
    .then(r => {
        console.log(r)
        // {message: "pong"}
    })

// call with a single parameter
dontmanage.call('dontmanage.core.doctype.user.user.get_role_profile', {
    role_profile: 'Test'
}).then(r => {
    console.log(r.message)
})

// call with all options
dontmanage.call({
    method: 'dontmanage.core.doctype.user.user.get_role_profile',
    args: {
        role_profile: 'Test'
    },
    // disable the button until the request is completed
    btn: $('.primary-action'),
    // freeze the screen until the request is completed
    freeze: true,
    callback: (r) => {
        // on success
    },
    error: (r) => {
        // on error
    }
})

dontmanage.db.get_doc

dontmanage.db.get_doc(doctype, name, filters)

Returns the Document object of doctype and name. If name is not provided, gets the first document matched by filters.

// get doc by name
dontmanage.db.get_doc('Task', 'TASK00002')
    .then(doc => {
        console.log(doc)
    })

// get doc by filters
dontmanage.db.get_doc('Task', null, { status: 'Open' })
    .then(doc => {
        console.log(doc)
    })

dontmanage.db.get_list

dontmanage.db.get_list(doctype, { fields, filters })

Returns a list of records of doctype with fields and filters.

dontmanage.db.get_list('Task', {
    fields: ['subject', 'description'],
    filters: {
        status: 'Open'
    }
}).then(records => {
    console.log(records);
})

dontmanage.db.get_value

dontmanage.db.get_value(doctype, name, fieldname)

Returns a document's field value or a list of values.

// single value
dontmanage.db.get_value('Task', 'TASK00004', 'status')
    .then(r => {
        console.log(r.message.status) // Open
    })

// multiple values
dontmanage.db.get_value('Task', 'TASK00004', ['status', 'subject'])
    .then(r => {
        let values = r.message;
        console.log(values.status, values.subject)
    })

// using filters
dontmanage.db.get_value('Task', {status: 'Open'}, 'subject')
    .then(r => {
        let values = r.message;
        console.log(values.subject)
    })

dontmanage.db.get_single_value

dontmanage.db.get_single_value(doctype, field)

Returns a field value from a Single DocType.

dontmanage.db.get_single_value('System Settings', 'time_zone')
    .then(time_zone => {
        console.log(time_zone);
    })

dontmanage.db.set_value

dontmanage.db.set_value(doctype, docname, fieldname, value, callback)

Sets a document's property using dontmanage.get_doc and doc.save on server.

// update a field's value
dontmanage.db.set_value('Task', 'TASK00004', 'status', 'Open')
    .then(r => {
        let doc = r.message;
        console.log(doc);
    })

// update multiple fields
dontmanage.db.set_value('Task', 'TASK00004', {
    status: 'Working',
    priority: 'Medium'
}).then(r => {
    let doc = r.message;
    console.log(doc);
})

dontmanage.db.insert

dontmanage.db.insert(doc)

Insert a new document.

dontmanage.db.insert({
    doctype: 'Task',
    subject: 'New Task'
}).then(doc => {
    console.log(doc);
})

dontmanage.db.count

dontmanage.db.count(doctype, filters)

Returns number of records for a given doctype and filters.

// total number of Task records
dontmanage.db.count('Task')
    .then(count => {
        console.log(count)
    })

// total number of Open Tasks
dontmanage.db.count('Task', { status: 'Open' })
    .then(count => {
        console.log(count)
    })

dontmanage.db.delete_doc

dontmanage.db.delete_doc(doctype, name)

Delete a document identified by doctype and name.

dontmanage.db.delete_doc('Task', 'TASK00004')

dontmanage.db.exists

dontmanage.db.exists(doctype, name)

Returns true if a document record exists.

dontmanage.db.exists('Task', 'TASK00004')
    .then(exists => {
        console.log(exists) // true
    })