Set value to table fields

How can i set the string value “Purchase Invoice” in the Type field of this table in custom script?

items.insert({"reference_doctype": "Purchase Invoice"})

But not worked…

The doctype of table:

@Leonardo_Augusto could you share you code and explain complete scenario

But my code don’t have nothing about table :confused:
I just wanna know how to set an string value to some table, can you give me an example?


frappe.ui.form.on("Purchase Invoice", "validate", function(frm) {
    $.each(frm.doc.parcelas || [], function(i, d) {
        // Create titulo{
		method: "erpnext.accounts.utils.make_titulo",
			vencimento_parcela: d.vencimento_parcela,
			valor_parcela: d.valor_parcela,
			bill_no: frm.doc.bill_no,
			posting_date: frm.doc.posting_date,
			supplier_name: frm.doc.supplier_name,
            callback: function(r)


def make_titulo(vencimento_parcela, valor_parcela, bill_no, posting_date, supplier_name, company):
        titulos = frappe.new_doc("Titulos")
        titulos.naming_series = "TIT-A-PAGAR-"
        titulos.tipo_parte = "Supplier"
        titulos.table_name.insert({reference_doctype: "Purchase Invoice"})  <- i wanna do this
        titulos.data_vencimento = vencimento_parcela
        titulos.valor_titulo = valor_parcela
        titulos.numero_nota = bill_no
        titulos.data_postagem = posting_date
        titulos.parte = supplier_name
        titulos.empresa = company

Any help?

@Leonardo_Augusto Could you explain exactly what are you trying to do in details?

When i run function make_payment_entry, the table “references” in ‘Payment Entry’ has to receive the string value “Purchase Invoice” in ‘reference_doctype’ docfield of table

Have a look at this ilnk:

How to use custom scripts


    frappe.ui.form.on('Your Doctype Name', 'refresh', function(frm){
    var a = "Payment Invoice"
    cur_frm.set_value("reference_name", a);


I did in server side, but i can’t test it cause I’m having problem with “Not permitted”

My personal opinion that client script is better for such requirements but still it’s your way.

Good Luck! :+1:


Thank you very much!

@Leonardo_Augusto Is it returning what you want?


where do you want to set this value?


In js i’ll do a frappe message for each titulos created, so i wanna show the name of them


Not works at all…

use this :

 callback: function(r)

For inserting new doctype and child table :

#This is child row
depend1 = frappe.get_doc({
        "doctype": "Task Depends On",
        "subject": "subject of the task",

#This is main doctype
task = frappe.get_doc({
        "doctype": "Task",
        "subject":  "subject of the task",
        "status": "Open",
    task.append("depends_on", depend1)

I hope this will help you

I don’t need do a get_doc cause i already have the values of fields, i just wanna set to table.
I just need do append, i’ll be trying, thanks for attention @Mohammed_Redha

@Mohammed_Redha how can i checkbox via script?