Why frappe.model.get_doc() returns null

When try to load details of student batch

using frappe.model.get()

var tlb = frappe.model.get_doc("Student Batch",'App Builder-TEST BATCH-2017-18');

and console.log(tlb);

i am getting null please help me to identify my error i tried few other student batches i get the same result for all

and when type select * from tabStudent Batch i am getting this

+-------------------------------------------+----------------------------+----------------------------+---------------+---------------+-----------+--------+-------------+------------+-----+---------------+-----------+---------+---------------+---------+-------------+-----------------------+------------+-----------+
| name                                      | creation                   | modified                   | modified_by   | owner         | docstatus | parent | parentfield | parenttype | idx | academic_year | _comments | enabled | academic_term | _assign | program     | student_batch_name    | _user_tags | _liked_by |
+-------------------------------------------+----------------------------+----------------------------+---------------+---------------+-----------+--------+-------------+------------+-----+---------------+-----------+---------+---------------+---------+-------------+-----------------------+------------+-----------+
| App Builder-abcd-2017-18                  | 2017-06-15 12:15:03.132846 | 2017-06-15 12:15:03.132846 | Administrator | Administrator |         0 | NULL   | NULL        | NULL       |   0 | 2017-18       | NULL      |       1 | NULL          | NULL    | App Builder | abcd                  | NULL       | NULL      |
| App Builder-APP BUILDER 2017-2018-2017-18 | 2017-05-09 11:13:00.092894 | 2017-06-01 07:38:13.370378 | Administrator | Administrator |         0 | NULL   | NULL        | NULL       |   0 | 2017-18       | NULL      |       1 | NULL          | NULL    | App Builder | APP BUILDER 2017-2018 | NULL       | NULL      |
| App Builder-TEST BATCH-2015-16            | 2017-06-15 12:03:31.715344 | 2017-06-19 08:08:16.945049 | Administrator | Administrator |         0 | NULL   | NULL        | NULL       |   0 | 2015-16       | NULL      |       1 | NULL          | NULL    | App Builder | TEST BATCH            | NULL       | NULL      |
| App Builder-TEST BATCH-2017-18            | 2017-06-12 08:24:28.257158 | 2017-06-12 08:24:50.130388 | Administrator | Administrator |         0 | NULL   | NULL        | NULL       |   0 | 2013-14       | NULL      |       1 | NULL          | NULL    | App Builder | TEST BATCH            | NULL       | NULL      |
+-------------------------------------------+----------------------------+----------------------------+---------------+---------------+-----------+--------+-------------+------------+-----+---------------+-----------+---------+---------------+---------+-------------+-----------------------+------------+-----------+

Hi, please try console.log(tlb.name)

@SwitsolAG when i tried using tlb.name i get an error

VM7751:117 Uncaught TypeError: Cannot read property ‘name’ of null(…)

hmmm, sorry it’s very strange everything works on my side.

@SwitsolAG where did you wrote the script

i wrote it in the student_applicant_list.js file

frappe.model.get_doc() will only return Student Batch record if it has loaded in the locals otherwise it will return null

@makarand_b so i can use this code only on student batch doctype page not in student applicant?

@makarand_b @SwitsolAG okey can you help me show how can i get details of student batch App Builder-TEST BATCH-2017-18 with out using locals

I suppose frappe.model.get_value("Student Batch",batch name, field_name) or using frappe.call

also gives me null

so i decided to do the frappe.call

@SwitsolAG @makarand_b thanks for your help

and i can’t see tick option which sets this as solved

You might have been using an async method. This is the proper way to do it within the .then()

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

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