此示例显示如何添加 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>
此示例代码在同一行中打印相关记录的所有记录标识,并以空格分隔。如果没有任何相关记录与该记录相关联,那么不打印任何内容。
#@EXPRESSION::if ( scalar( @{#?RelatedRecords?#} ) ) { "Related Records: ".join(" ",@{#?RelatedRecords?#}); } else { ""; }@#
此示例代码打印状态字段的当前值,如果此字段已更改,那么还将打印状态字段的先前值。
State: #?State?# #@EXPRESSION::if (#?State?# ne #%State%#) { "(Old Value: ". #%State%# .")"; }@#
尽管字段元标记可以在 EmailPlus 表达式中使用,但偶尔可能无法正确对表达式进行求值。特别是,如果字段值包含奇数个双引号或单引号,那么无法正确地对表达式求值。在此情况下,您可以使用 EmailPlus 全局脚本中的函数来解析字段值,而非使用字段元标记。此外,使用 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;
@#