Custom Script to Select Print Format

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.

2 Likes

Any help on this? I have the same problem and based on the view count so did others.

1 Like

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? :wink:

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

@ArundhatiS I created an issue in github (#7849)

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.

1 Like

Hi,

have you found solution for this problem?

Best regards!

@jpuskar I use custom script to set the print format and header.

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 = " ";
}

};

@Rudi_Meylemans thank you for the script.

Best regards!

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.