Set value to table fields

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

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?

JS:

frappe.ui.form.on("Purchase Invoice", "validate", function(frm) {
    $.each(frm.doc.parcelas || [], function(i, d) {
        // Create titulo
        frappe.call({
		method: "erpnext.accounts.utils.make_titulo",
		args:{    
			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,
			company: frm.doc.company,
		},
            callback: function(r)
            {console.log(r)}
        });
    });
});

PY:

@frappe.whitelist()
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
        titulos.save()
        return titulos.name

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

Example:

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

@Faraz

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:

@Faraz

Thank you very much!

@Leonardo_Augusto Is it returning what you want?

{console.log(r)}

where do you want to set this value?

return titulos.name

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

@Mohammed_Redha
Tried:
https://github.com/leonardoaugt/financeiro/blob/master/financeiro/financeiro/doctype/titulos/titulos.py#L39

Not works at all…

use this :

 callback: function(r)
            {
 msgprint(r.message.name);
}
        });

For inserting new doctype and child table :

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

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

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?