Never thought clicking Print icon on a record to get the pdf WILL fire record’s user event. This is very new to me
function _beforeSubmit(context) {
if (context.type !== 'print') return;
var rec = context.newRecord;
var amountTotal = rec.getValue({ fieldId: 'total' });
var amountChinese = getAmountChinese(amountTotal);
log.debug('order amount: ' + amountTotal, 'amount Chinese: ' + amountChinese);
var form = context.form;
var field = form.addField({
id: 'custpage_total_amount_text_p', type: serverWidget.FieldType.TEXT, label: 'amount in cn'
});
field.defaultValue = amountChinese;
rec.setValue({ fieldId: 'custbody_total_amount_text', value: amountChinese });
}
In this example, when print the record where the user event script like above is deployed to will fire the function getAmountChinese
and the field custbody_total_amount_text
will become available for the Advanced PDF Template, as snippet shown below.
<tr height="30px">
<td colspan="2">运费(RMB)</td>
<td colspan="3">${record.custbody_po_shipping_fee}</td>
<td colspan="3">合计金额(大写)</td>
<td colspan="4">${record.custpage_total_amount_text_p}</td>
</tr>
This is fairly new to me because I never thought UE would be fired when print, but it does make some sense since printing is a typical user event as it retrieves data on a record basis.
没想到单据上的打印按钮能触发UE脚本,很神奇。懒得写中文部分了就这样吧
Comments
Thx!