I want to add a doctype button same as Opportunity on Lead’s Dashboard using custom script.
Is it possible ?
If so, guide me through this.
Thanks
I want to add a doctype button same as Opportunity on Lead’s Dashboard using custom script.
Is it possible ?
If so, guide me through this.
Thanks
@Leonardo_Augusto , I have created doctype xyz . I need to add that doctype on lead’s dashboard using custom script.
Thanks
@Leonardo_Augusto, it’s working but i getting error message the resource you are looking not available.
Thank You
can you share your script?
@johnskywalker, sure
frappe.ui.form.on(‘Lead’, {
refresh: function(frm) {
dashboard_link_doctype(frm, “Risk Profile”);
}
});
dashboard_link_doctype = function (frm, doctype){
var parent = $('.form-dashboard-wrapper [data-doctype="Quotation"]').closest('div').parent();
parent.find('[data-doctype="'+doctype+'"]').remove();
parent.append(frappe.render_template("dashboard_link_doctype", {doctype:doctype}));
var self = parent.find('[data-doctype="'+doctype+'"]');
set_open_count(frm, doctype);
// bind links
self.find(".badge-link").on('click', function() {
frappe.route_options = {"quotation": frm.doc.name}
frappe.set_route("List", doctype);
});
// bind open notifications
self.find('.open-notification').on('click', function() {
frappe.route_options = {
"quotation": frm.doc.name,
"status": "Draft"
}
frappe.set_route("List", doctype);
});
// bind new
if(frappe.model.can_create(doctype)) {
self.find('.btn-new').removeClass('hidden');
}
self.find('.btn-new').on('click', function() {
frappe.new_doc(doctype,{
"quotation": frm.doc.name
});
});
}
set_open_count = function (frm, doctype){
var method = '';
var links = {};
if(doctype=="Risk Profile"){
method = 'my_app.api.get_open_count';
links = {
'fieldname': 'prevdoc_docname',
'transactions': [
{
'label': __('Risk Profile'),
'items': ['Risk Profile']
},
]
};
}
if(method!=""){
frappe.call({
type: "GET",
method: method,
args: {
doctype: frm.doctype,
name: frm.doc.name,
links: links,
},
callback: function(r) {
// update badges
$.each(r.message.count, function(i, d) {
frm.dashboard.set_badge_count(d.name, cint(d.open_count), cint(d.count));
});
}
});
}
}
frappe.templates["dashboard_link_doctype"] = ' \
<div class="document-link" data-doctype="{{ doctype }}"> \
<a class="badge-link small">{{ __(doctype) }}</a> \
<span class="text-muted small count"></span> \
<span class="open-notification hidden" title="{{ __("Open {0}", [__(doctype)])}}"></span> \
<button class="btn btn-new btn-default btn-xs hidden" data-doctype="{{ doctype }}"> \
<i class="octicon octicon-plus" style="font-size: 12px;"></i> \
</button>\
</div>';
Thank You
If waiting isn’t an issue then lets hope this gets merged soon
https://github.com/frappe/frappe/pull/5861
Rather than doing all the javascript workaround, we should try to make it generic and have it pushed in the core so that everyone can use it
@Zlash65 but it gives me error :
TypeError: this.frm.dashboard.add_transactions is not a function
Thank Your
That was just an example on how to use it. Basically you need the ‘form’ object which could be frm
or cur_frm
or this.frm
depending on how you are using it. If you are using it through custom script directly, you might want to use cur_frm
.
Also, did you pull the pr ? Its not merged yet so ?
I found the Solution through custom script.
Please provide/post Solution with custom script
below are the custom script:
frappe.ui.form.on('Lead',
{
refresh: function(frm)
{
dashboard_link_doctype(frm, "Risk Profile");
}
});
dashboard_link_doctype = function(frm, doctype)
{
var parent = $('.form-dashboard-wrapper [data-doctype="Quotation"]').closest('div').parent();
parent.find('[data-doctype="' + doctype + '"]').remove();
parent.append(frappe.render_template("dashboard_link_doctype",
{
doctype: doctype
}));
var self = parent.find('[data-doctype="' + doctype + '"]');
//set_open_count(frm, doctype);
// bind links
self.find(".badge-link").on('click', function()
{
frappe.route_options = {
"lead": frm.doc.name
}
frappe.set_route("List", doctype);
});
// bind open notifications
self.find('.open-notification').on('click', function()
{
frappe.route_options = {
"lead": frm.doc.name,
"status": "lead"
}
frappe.set_route("List", doctype);
});
// bind new
if (frappe.model.can_create(doctype))
{
self.find('.btn-new').removeClass('hidden');
}
self.find('.btn-new').on('click', function()
{
frappe.new_doc(doctype,
{
"lead": frm.doc.name
});
});
}
set_open_count = function(frm, doctype)
{
var method = '';
var links = {};
if (doctype == "Risk Profile")
{
method = 'frappe.client.get_open_count';
links = {
'fieldname': 'lead',
'transactions': [
{
'label': __('Risk Profile'),
'items': ['Risk Profile']
}, ]
};
}
if (method != "")
{
frappe.call(
{
type: "GET",
method: method,
args:
{
doctype: frm.doctype,
name: frm.doc.name,
links: links,
},
callback: function(r)
{
// update badges
$.each(r.message.count, function(i, d)
{
frm.dashboard.set_badge_count(d.name, cint(d.open_count), cint(d.count));
});
}
});
}
}
frappe.templates["dashboard_link_doctype"] = ' \
<div class="document-link" data-doctype="{{ doctype }}"> \
<a class="badge-link small">{{ __(doctype) }}</a> \
<span class="text-muted small count"></span> \
<span class="open-notification hidden" title="{{ __("Open {0}", [__(doctype)])}}"></span> \
<button class="btn btn-new btn-default btn-xs hidden" data-doctype="{{ doctype }}"> \
<i class="octicon octicon-plus" style="font-size: 12px;"></i> \
</button>\
</div>';