Adding tag programmatically

Example if I have inserted a new journal entry code below.

jv = frappe.get_doc({
  "doctype": "Journal Entry",
  "posting_date": "2015-01-01",
  "accounts": [{
    "account": ...
  }],
  ...
})
jv.insert()

How can I add programmatically a tag to this?

https://frappe.github.io/frappe/current/api/desk/frappe.desk.tags.html#frappe.desk.tags.add_tag

1 Like

@rmehta I am a little lost how to use this one :frowning:

jv = frappe.get_doc({
  "doctype": "Journal Entry",
  "posting_date": "2015-01-01",
  "accounts": [{
    "account": ...
  }],
  ...
})
jv.insert()
frappe.desk.tags.add(jv, "test")

Adding frappe.desk.tags.add(jv, “test”) got an error 'module' object has no attribute 'tags'. What is the right way to add tags in a document? Sorry for being so noobs for this one.

@ccfiel do you need import tags at the head!

from frappe.desk import tags

....
tags.add(jv, 'test')

@max_morais_dmm @rmehta I got how to use it! :smile: DocTags("Journal Entry").add(journal.name, "test") . Thanks!

from frappe.desk.tags import DocTags

jv = frappe.get_doc({
  "doctype": "Journal Entry",
  "posting_date": "2015-01-01",
  "accounts": [{
    "account": ...
  }],
  ...
})
jv.insert()
DocTags("Journal Entry").add(journal.name, "test")
1 Like