此範例會顯示如何新增 HTML 程式碼,以視優先順序欄位的值來變更文字的顏色。如果優先順序具有值 1,則文字會以紅色顯示。
#@EXPRESSION::if ( #?Priority?# eq "1 - High" ) {"<FONT COLOR=\"red\">";} elsif ( #?Priority?# eq "2 - Medium" ) { "<FONT COLOR=\"orange\">";} elsif ( #?Priority?# eq "3 - Low" ) { "<FONT COLOR=\"yellow\">";}@#Priority: #?Priority?# </FONT>
此程式碼範例會將相關記錄列印所有記錄 ID 列印在同一行上,以空格區隔。如果沒有與記錄相關聯的相關記錄,則不會列印任何項目。
#@EXPRESSION::if ( scalar( @{#?RelatedRecords?#} ) ) { "Related Records: ".join(" ",@{#?RelatedRecords?#}); } else { ""; }@#
此程式碼範例會列印狀態欄位的現行值,且如果此值曾經變更,則也會列印狀態欄位的前一個值。
State: #?State?# #@EXPRESSION::if (#?State?# ne #%State%#) { "(Old Value: ". #%State%# .")"; }@#
雖然可在 EmailPlus 表示式中使用欄位 meta 標籤,但是偶爾可能無法正確地評估表示式。明確地說,如果欄位值包含奇數的雙引號或單引號,則無法正確地評估表示式。在此情況下,您可以使用 EmailPlus 廣域 Script 中的函數來解析欄位值,而非使用欄位 meta 標籤。此外,還可使用 quotemeta Perl 函數,來跳出欄位值中的任何非英數字元。您可以利用此函數,有效地比較 EmailPlus 表示式中的欄位值。此範例會比較說明欄位的欄位值與說明欄位的原始欄位值。如果它們不同,則 EmailPlus 通知會包括一則訊息,陳述說明欄位已變更。
#@EXPRESSION::if ( quotemeta(Gfv("Description")) ne quotemeta(Gfov("Description") ) { "The Description field has changed: “.Gfv(“Description") ; }@#
下列範例會將記錄附件的詳細資料新增至通知。如需新增的詳細資料的相關說明,請參閱程式碼中的註解:
#@EXPRESSION::
# Get a list of the attachment fields in this record type...
my($AttachmentFields) = $entity->GetAttachmentFields();
# Tell how many attachment fields there are and show their
# names...
$M = $M . "This entity contains " . $AttachmentFields->Count() .
" attachment field(s)\n";
for ($A = 0; $A < $AttachmentFields->Count(); $A++)
{
$M = $M . " " . ($AttachmentFields->Item($A) )->GetFieldName() . "\n";
}
$M .= "\n";
# Iterate over the attachment fields; for each one, list the
# attachments it contains in the current record...
for (my($AF) = 0; $AF <$AttachmentFields->Count(); $AF++) {
my ($AttachmentField) = $AttachmentFields->Item($AF);
$M = $M ."Attachment field '"
. $AttachmentField->GetFieldName().
"' contains:\n";
# Iterate over the attachments in this field...
my($Attachments) = $AttachmentField->GetAttachments();
for (my($A) = 0; $A <$Attachments->Count(); $A++) {
my($Attachment) = $Attachments->Item($A);
# Report info about this attachment...
$M = $M .
" Filename='" . $Attachment->GetFileName() . "'" .
" FileSize=" . $Attachment->GetFileSize() .
" Description='" . $Attachment->GetDescription() . "'" .
"\n";
}
$M = $M ."Total attachments: ". $Attachments->Count() ."\n\n";
}
# Display the results...
$M;
@#