I have button script for my custom single doctype, when i have editing the form button is showing, but after save it’s not it disappearing and when i refresh tab it’s showing and working well
frappe.ui.form.on('Doctype', {
onload: function(frm) {
frm.add_custom_button(__('📋 Copy Text'), function() {
var description = frm.doc.description || '';
var model = frm.doc.model || '';
var price = parseFloat(frm.doc.price) || 0;
var discount = parseFloat(frm.doc.discount) || 0;
var subTotal = price - (price * (discount / 100));
var gst = subTotal * 0.18; // Assuming 18% GST
var grandTotal = subTotal + gst;
var producturl = frm.doc.product_url;
var fixLink = frm.doc.fix_link; // New field
var formattedPrice = price.toLocaleString('en-IN', { style: 'currency', currency: 'INR', minimumFractionDigits: 2, maximumFractionDigits: 2 });
var formattedDiscount = (price * discount / 100).toLocaleString('en-IN', { style: 'currency', currency: 'INR', minimumFractionDigits: 2, maximumFractionDigits: 2 });
var formattedSubTotal = subTotal.toLocaleString('en-IN', { style: 'currency', currency: 'INR', minimumFractionDigits: 2, maximumFractionDigits: 2 });
var formattedGST = Math.round(gst).toLocaleString('en-IN', { style: 'currency', currency: 'INR' });
var formattedGrandTotal = Math.round(grandTotal).toLocaleString('en-IN', { style: 'currency', currency: 'INR' });
var formattedText = `Model : *[model]*\n
[description]\n
MESSAGE
`;
if (producturl) {
formattedText += `
🔍 View More : [product_url]
----------------------------------------------------------`;
}
if (fixLink) {
formattedText += `
🔔 Connect With Us : [fix_link]`;
}
formattedText = formattedText.replace('[description]', description);
formattedText = formattedText.replace('[discount]', discount.toFixed(0));
formattedText = formattedText.replace('[model]', model);
formattedText = formattedText.replace('[product_url]', producturl);
formattedText = formattedText.replace('[fix_link]', fixLink); // Replace the fix_link placeholder
var textArea = document.createElement("textarea");
textArea.value = formattedText;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
frm.set_value('preview_message', formattedText);
frappe.show_alert({
message: 'Message Copied Successfully',
indicator: 'green',
persist: 3 // Duration
});
});
}
});