Difference between revisions of "Notification Examples"
m (1 revision) |
|||
Line 216: | Line 216: | ||
<br /><br /> | <br /><br /> | ||
+ | == Sending HTML Emails == | ||
+ | We need to specify proper '''content type''' in the message header ("Header add-in" field). When it is done, we can use HTML in the message body, highlighting text, using different fonts and colors, etc. | ||
+ | |||
+ | <br /> Notification rule:<br /> | ||
+ | |||
+ | {| width="100%" border="1" cellspacing="2" cellpadding="2" | ||
+ | ! width="20%" valign="top" | Form Field Name<br /> (CQ field name)<br /> | ||
+ | ! valign="top" | Value<br /> | ||
+ | |- | ||
+ | | width="20%" valign="top" | Name<br /> (name)<br /> | ||
+ | | valign="top" | My first HTML email<br /> | ||
+ | |- | ||
+ | | width="20%" valign="top" | Record Type<br /> (Entity_Def)<br /> | ||
+ | | valign="top" | Defect<br /> | ||
+ | |- | ||
+ | | valign="top" | Header add-in<br /> (Msg_Header)<br /> | ||
+ | | valign="top" | '''Content-Type: text/html; charset=us-ascii''' | ||
+ | |- | ||
+ | | valign="top" | To<br /> (Msg_To_Users)<br /> | ||
+ | | valign="top" | '''$owner.email<br />''' | ||
+ | |- | ||
+ | | valign="top" | Subject<br /> (Msg_Subject) | ||
+ | | valign="top" | HTML test message for defect ''''$ID'''' | ||
+ | |- | ||
+ | | valign="top" | Body<br /> (Msg_Body)<br /> | ||
+ | | valign="top" | <source lang="xml"> | ||
+ | <HTML> <BODY> | ||
+ | <H2 ALIGN="left">$EntityDefName $ID</H2> | ||
+ | <TABLE ALIGN="left" BORDER="1"> | ||
+ | <TR><TD><b>ID</b> </TD> <TD>$id </TD></TR> | ||
+ | <TR><TD><b>headline</b></TD> <TD>$Headline</TD></TR> | ||
+ | <TR><TD><b>Priority</b></TD> <TD>$Priority</TD></TR> | ||
+ | <TR><TD><b>Severity</b></TD> <TD>$Severity</TD></TR> | ||
+ | <TR><TD><b>Description</b></TD> | ||
+ | <TD><PRE>$Description</PRE> </TD></TR> | ||
+ | </TABLE> </BODY> </HTML> </source> | ||
+ | |} | ||
+ | |||
+ | <br /><br /> | ||
[[Category:Email_Notification_Package]] | [[Category:Email_Notification_Package]] |
Revision as of 20:10, 21 August 2011
Contents
Defect state updates
Send notification to submitter ('Submitter' CQ field - reference to users) when Defect is postponed (with action postpone), rejected (with action reject) or closed (action close).
Do not send notification if submitter is the same user that perform action to avoid email flooding.
We have to test notification rule in test database and migrate it to production without changes (database name in http link should be updated automatically).
lets define two functions in database properties:
udb_property records:
Name |
nm_value |
---|---|
GetUserLoginName |
return $session->GetUserLoginName();
|
GetCurrentDatabaseName |
my $dbname = $session->GetSessionDatabase()->GetDatabaseName();
return $dbname;
|
Email_Notification_Rule fields:
Form Field Name (CQ field name) |
Value |
---|---|
Name (name) |
State change submitter notification (any unique name) |
Record Type (Entity_Def) |
Defect |
Actions (actions) |
Postpone Reject Close |
Condition (Msg_Condition) |
GetUserLoginName() ne $Submitter |
To (Msg_To_Users) |
$Submitter.email |
Subject (Msg_Subject) |
Your Defect '$ID' has been ${state}. |
Body (Msg_Body) |
Your Defect '$ID' has been ${state}. Defect title: '$Headline' http://newcqweb-server/cqweb/main?USE_CASE=GO&service=CQ&schema=DBSET&contextid=GetCurrentDatabaseName()&entityID=${dbid}&entityDefName=Defect |
Subject will be evaluated when email notification is triggered, for example:
"Your Defect 'SAMPL00000001' has been Rejected."
We use ${State} notation for state field to avoid ambiguity, because it is followed by '.' (valid symbol for variable name).
Using SQL query
Send notification to clearquest user group 'CCB_Approvers' and submitter when request been resolved
Form Field Name (CQ field name) |
Value |
---|---|
Name (name) |
Resolution Notification (any unique name) |
Record Type (Entity_Def) |
Defect |
Actions (actions) |
Resolve |
To (Msg_To_Users) |
$Submitter.email SQL("SELECT T2.email FROM parent_child_links T1, groups T3, users T2 WHERE T1.parent_dbid = T2.dbid AND T1.child_dbid = T3.dbid AND T3.name = 'CCB_Approvers' AND T2.is_active = 1") |
Subject (Msg_Subject) |
Defect '$ID' has been resolved. Resolution '$Resolution' |
Body (Msg_Body) |
Defect '$ID' has been resolved. Defect title: '$Headline' Resolution: '$Resolution' Description: $Description http://newcqweb-server/cqweb/main?USE_CASE=GO&service=CQ&schema=DBSET&contextid=GetCurrentDatabaseName()&entityID=${dbid}&entityDefName=Defect |
You can also create reusable function and put it into properties
udb_property record
Name |
nm_value |
---|---|
GetGroupEmailAddresses |
my ($groupname) = @_;
my $return_string;
# SQL statement
my $result_set = $session->BuildSQLQuery(
"SELECT T2.email
FROM parent_child_links T1, groups T3, users T2
WHERE T1.parent_dbid = T2.dbid
AND T1.child_dbid = T3.dbid
AND T3.name = '$groupname'
AND T2.is_active = 1");
$result_set->Execute();
# fetch email addresses
while( $result_set->MoveNext() == $CQPerlExt::CQ_SUCCESS ){
my $tmp_str = $result_set->GetColumnValue(1);
$return_string .= "$tmp_str\n";
}
# clear 'errors'
$result_set = undef;
$@ = '';
return $return_string;
|
In this case 'To' field in Notification rule could be changed to:
Form Field Name (CQ field name) |
Value |
---|---|
To (Msg_To_Users) |
$Submitter.email GetGroupEmailAddresses( 'CCB_Approvers' ) |
SQL query and dynamically assigned message priority
To simplify defect management, we use assignment or functional group idea.
Defect submitters do not know who is responsible for particular feature, but can guess, what functional area is.
Submitter needs to select Assignment group only.
We need to notify Assignment group manager(s) about new defect assigned to group.
If defect Severity is '1-Critical' or Priority is '1-Resolve Immediately', email message has to be flagged as 'High Priority'.
Possible AssignmentGroups stateless record type implementation:
Name | SHORT_STRING |
Unique group name |
Managers |
REFERENCE to users |
group managers |
Users |
REFERENCE to users | group members |
Active | INT |
obsolete groups marked as '0', valid groups as '1' |
Defect record type has Assigned_To_Group field (reference to AssignmentGroups).
Form Field Name (CQ field name) |
Value |
---|---|
Name (name) |
Notify Group Managers (any unique name) |
Record Type (Entity_Def) |
Defect |
Field Change (Field_Change) |
Assigned_To_Group |
Priority (Msg_Priority) |
$Priority =~ /^1/ || $Severity =~ /^1/ |
To (Msg_To_Users) |
SQL("SELECT T3.email FROM parent_child_links T1, fielddef T2, users T3, assignmentgroups T4 WHERE T1.parent_dbid = T4.dbid AND T1.child_dbid = T3.dbid AND T1.parent_fielddef_id = T2.id AND T2.name = 'Managers' AND T4.name = '${Assigned_To_Group}' ") |
Subject (Msg_Subject) |
Defect '$ID' with severity: '$Severity' and priority: '$Priority' has been assigned to your team. Please assign it to somebody in your team. |
Body (Msg_Body) |
Defect '$ID' has been assigned to your team. Please assign Defect to somebody in your team or re-assign it to another team if initial assignment was incorrect. Defect title: '$Headline' Severity: '$Severity' Priority: '$Priority' Description: $Description http://newcqweb-server/cqweb/main?USE_CASE=GO&service=CQ&schema=DBSET&contextid=GetCurrentDatabaseName()&entityID=${dbid}&entityDefName=Defect |
Using original field value
Notify assignee that defect priority assigned to him has been raised. Valid priorities are '1- something', '2 - something', etc. That simplifies comparison.
Lets create user-defined function that retrieves previous value for field.
udb_property record
Name |
nm_value |
---|---|
GetFieldOriginalValue |
my $name = shift;
my $value = '' ;
eval {
$value = $entity->GetFieldOriginalValue($name)->GetValue();
};
$@ = '';
return $value;
|
Notification rule:
Form Field Name (CQ field name) |
Value |
---|---|
Name (name) |
Priority has been raised - notify assignee |
Record Type (Entity_Def) |
Defect |
Field Change (Field_Change) |
Priority |
Condition (Msg_Condition) |
$Priority gt GetFieldOriginalValue('Priority') |
To (Msg_To_Users) |
$owner.email |
Subject (Msg_Subject) |
Priority has been raised for defect '$ID' from 'GetFieldOriginalValue('Priority')' to '$Priority' |
Body (Msg_Body) |
Priority has been raised for defect '$ID' from 'GetFieldOriginalValue('Priority')' to '$Priority' Defect title: '$Headline' Severity: '$Severity' Priority: '$Priority' Description: $Description http://newcqweb-server/cqweb/main?USE_CASE=GO&service=CQ&schema=DBSET&contextid=GetCurrentDatabaseName()&entityID=${dbid}&entityDefName=Defect |
Sending HTML Emails
We need to specify proper content type in the message header ("Header add-in" field). When it is done, we can use HTML in the message body, highlighting text, using different fonts and colors, etc.
Notification rule:
Form Field Name (CQ field name) |
Value |
---|---|
Name (name) |
My first HTML email |
Record Type (Entity_Def) |
Defect |
Header add-in (Msg_Header) |
Content-Type: text/html; charset=us-ascii |
To (Msg_To_Users) |
$owner.email |
Subject (Msg_Subject) |
HTML test message for defect '$ID' |
Body (Msg_Body) |
<HTML> <BODY>
<H2 ALIGN="left">$EntityDefName $ID</H2>
<TABLE ALIGN="left" BORDER="1">
<TR><TD><b>ID</b> </TD> <TD>$id </TD></TR>
<TR><TD><b>headline</b></TD> <TD>$Headline</TD></TR>
<TR><TD><b>Priority</b></TD> <TD>$Priority</TD></TR>
<TR><TD><b>Severity</b></TD> <TD>$Severity</TD></TR>
<TR><TD><b>Description</b></TD>
<TD><PRE>$Description</PRE> </TD></TR>
</TABLE> </BODY> </HTML>
|