Is there a way to programatically set the print format using a custom script?
Hello,
Please elaborate your requirement. Will there be some criteria based on which print format will be set? An example will be helpful.
For now, you can set default Print Format for the document from Customize Form. This allows you to set even custom print format as default.
Example: When I change the Purchase Invoice âSeriesâ, I would like to have the Print Format changed from âStandardâ to âMy Print Formatâ.
Basically depending on the Series I would like to different print formats selected automatically.
Any help on this? I have the same problem and based on the view count so did others.
Any news on this? I would also need this functionality as a use quotation for 2 different types and they have both their print format.
@Rudi_Meylemans
This feature is available for now. Request you to please create a github feature suggestion for the same.
Thanks
Is it available or not?
Can you explain more? Is the feature available or do I need to raise a request in github?
@Rudi_Meylemans
Sorry for but the feature isnât available for now. Please create a github feature suggestion for the same.
Thanks
Thanks. For now, you can manually set default Print Format for a Doctype (say Sales Invoice) from Customize Form. So, after changing the series, you will just to need to update default Print Format for a Doctype in the Customize Form.
Yes that is what we do now. But often people forget to change and print using the wrong format. So scripting would solve this.
Hi,
have you found solution for this problem?
Best regards!
please share your code
This is the code I use for quotation
frappe.ui.form.on(âQuotationâ, âonloadâ, function(frm){
if (!frm.doc.company) {
frm.set_value(âcompanyâ, âMampaey Engineering BVBAâ);
};
frm.set_value(âletter_headâ, âBVBA Quotationâ);
if (frm.doc.company == âMampaey Engineering & Co NVâ) {
frm.set_value(âletter_headâ, âNV Quotationâ);
};
frm.add_fetch(âcustomerâ, âbvba_leverancier_nrâ, âlevbvbaâ);
frm.add_fetch(âcustomerâ, ânv_leverancier_nrâ, âlevnvâ);
});
// Company based on naming series
frappe.ui.form.on(âQuotationâ, ânaming_seriesâ, function(frm, cdt, cdn){
frappe.after_ajax(function() {
var d = locals[cdt][cdn];
if (frm.doc.naming_series == âQTN-.YY.M-â) {
frm.set_value(âcompanyâ, âMampaey Engineering & Co NVâ);
frm.set_value(âletter_headâ, âNV Quotationâ);
frm.set_value(âme_leverancier_nrâ, frm.doc.levnv);
};
if (frm.doc.naming_series == âQTN-.YY.H-â) {
frm.set_value(âcompanyâ, âMampaey Engineering & Co NVâ);
frm.set_value(âletter_headâ, âNV Bestekâ);
frm.set_value(âme_leverancier_nrâ, frm.doc.levnv);
};
if (frm.doc.naming_series == âQTN-M.YY.-â) {
frm.set_value(âcompanyâ, âMampaey Engineering BVBAâ);
frm.set_value(âletter_headâ, âBVBA Quotationâ);
frm.set_value(âme_leverancier_nrâ, frm.doc.levbvba);
};
if (frm.doc.naming_series == âQTN-H.YY.-â) {
frm.set_value(âcompanyâ, âMampaey Engineering BVBAâ);
frm.set_value(âletter_headâ, âBVBA Bestekâ);
frm.set_value(âme_leverancier_nrâ, frm.doc.levbvba);
};
frm.refresh_field(âme_leverancierâ);
});
});
// leverancier nummer ophalen
frappe.ui.form.on(âQuotationâ, âcustomerâ, function(frm, cdt, cdn){
frappe.after_ajax(function() {
var d = locals[cdt][cdn];
if (frm.doc.company == âMampaey Engineering & Co NVâ) {
frm.add_fetch(âcustomerâ, ânv_leverancier_nrâ, âme_leverancier_nrâ);
};
if (frm.doc.company == âMampaey Engineering BVBAâ) {
frm.add_fetch(âcustomerâ, âbvba_leverancier_nrâ, âme_leverancier_nrâ);
};
frm.add_fetch(âcustomerâ, âlanguageâ, âtaalâ);
if (frm.doc.naming_series == âQTN-.YY.M-â) {
frm.set_value(âletter_headâ, âNV Quotationâ);
};
if (frm.doc.naming_series == âQTN-.YY.H-â) {
frm.set_value(âletter_headâ, âNV Bestekâ);
};
if (frm.doc.naming_series == âQTN-M.YY.-â) {
frm.set_value(âletter_headâ, âBVBA Quotationâ);
};
if (frm.doc.naming_series == âQTN-H.YY.-â) {
frm.set_value(âletter_headâ, âBVBA Bestekâ);
};
});
});
cur_frm.add_fetch(âitem_codeâ, âlange_omschrijvingâ, âlange_omschrijvingâ);
cur_frm.cscript.custom_validate = function(doc) {
// clear chauveheid
doc.chauveheid= " ";
// chauveheid is based on user
switch(user) {
case "manu@mampaey-engineering.be":
doc.chauveheid = "Service Center : Chauveheid 124 - B4987 Stoumont - Tel: 086/43 43 01 - Fax 086/43 43 80";
break;
default:
doc.chauveheid = " ";
}
};
Thank you for your post, actually I need this more in my case, please if you achieve any solution, share it with me
Thank you in advance.