Difference between revisions of "Generate Notifications Only for Employee Comments"

From SDU
Jump to: navigation, search
 
m (Step 1. Create the scripts)
 
(2 intermediate revisions by the same user not shown)
Line 20: Line 20:
 
{{Create Spell Script}}
 
{{Create Spell Script}}
  
The first script is triggered on the Act_Log table and writes a simple value to an unused field (string2) in the Call_Req table. You can change this to any of the unused stringX fields that you like. The script assumes that the Employee Access Type is associated with the Employee Interface and that it is also set as the default Access Type.
+
This script is triggered on the Act_Log table and attaches an event to the ticket. The script assumes that the Employee Access Type is associated with the Employee Interface and that it is also set as the default Access Type.
<source lang="javascript">alg::myscript1(...) {
+
<source lang="javascript">alg::zemp_comment(...) {
 +
// The following IF STATEMENT assumes that 2405 is the id of the Employee Access Type
 +
// and that the Employee Access Type is the default.
 
if (analyst.access_type == 2405 || is_null(analyst.access_type)) {
 
if (analyst.access_type == 2405 || is_null(analyst.access_type)) {
send_wait(0, this, "call_attr", "call_req_id.string2", "set_val", type, "SURE_SET");
+
object attached_events_table_record, group_leader;
if (msg_error()) {
+
logf(ERROR, "error setting string2 to %s on %s %s - %s", type, call_req_id.type.sym, call_req_id.ref_num, msg[0]);
+
return;
+
} else {
+
logf(SIGNIFICANT, "successfully set string2 to %s on %s %s", type, call_req_id.type.sym, call_req_id.ref_num);
+
}
+
}
+
}</source>
+
 
+
The second script is triggered when the update to the string2 field is initiated by the previous script. Again, you can change this to any stringX field as needed. Once the condition for notification is met, an event is attached. The event will trigger the macro that will send the notification.
+
<source lang="javascript">cr::myscript2(...){
+
send_wait( 0, this, "get_attr_vals",1,"string2");
+
if (msg_error()) {
+
logf(ERROR, "error getting string2 for %s %s - %s", type.sym, ref_num, msg[0]);
+
return;
+
}
+
string z_string2;
+
z_string2 = msg[3];
+
if (z_string2 == 'LOG') {
+
 
string z_evt;
 
string z_evt;
// Enter the persid of the event to get attached to the ticket.
+
// Identify below the id of the event to attach.
 
z_evt = "evt:400001";
 
z_evt = "evt:400001";
// Clear string2
+
 
send_wait(0, this, "call_attr", "string2", "set_val", "", "SURE_SET");
+
if (!is_null(call_req_id.assignee)) {
if (msg_error()) {
+
send_wait(0, top_object(), "get_co_group");
logf(ERROR, "error clearing string2 on %s %s - %s", type.sym, ref_num, msg[0]);
+
if (msg_error()) {
return;
+
logf(ERROR, "%s %s - %s", call_req_id.type.sym, call_req_id.ref_num, msg[0]);
} else {
+
}
logf(SIGNIFICANT, "successfully cleared string2 on %s %s", type.sym, ref_num);
+
group_leader = msg[0];
}
+
send_wait(0, top_object(), "call_attr", "atev", "get_new_dob", NULL, NULL, group_leader);
// Attach event that generates notication
+
if (msg_error()) {
object group_leader;
+
logf(ERROR, "%s %s - %s", call_req_id.type.sym, call_req_id.ref_num, msg[0]);
object attached_events_table_record;
+
}
send_wait(0, top_object(), "get_co_group");
+
attached_events_table_record = msg[0];
if (msg_error()) {
+
attached_events_table_record.obj_id = call_req_id;
logf(ERROR, "%s %s - %s", type.sym, ref_num, msg[0]);
+
attached_events_table_record.event_tmpl = z_evt;
}
+
send_wait(0, group_leader, "checkin");
group_leader = msg[0];
+
if (msg_error()) {
send_wait(0, top_object(), "call_attr", "atev", "get_new_dob", NULL, NULL, group_leader);
+
logf(ERROR, "error attaching event %s to %s %s - %s", z_evt, call_req_id.type.sym, call_req_id.ref_num, msg[0]);
if (msg_error()) {
+
} else {
logf(ERROR, "%s %s - %s", type.sym, ref_num, msg[0]);
+
logf(SIGNIFICANT, "successfully attached event %s to %s %s", z_evt, call_req_id.type.sym, call_req_id.ref_num);
}
+
}
attached_events_table_record = msg[0];
+
attached_events_table_record.obj_id = persistent_id;
+
attached_events_table_record.event_tmpl = z_evt;
+
send_wait(0, group_leader, "checkin");
+
if (msg_error()) {
+
logf(ERROR, "error attaching event %s to %s %s - %s", z_evt, type.sym, ref_num, msg[0]);
+
return;
+
} else {
+
logf(SIGNIFICANT, "successfully attached event %s to %s %s", z_evt, type.sym, ref_num);
+
 
}
 
}
 
}
 
}
Line 80: Line 54:
  
 
=== Step 2. Create the triggers ===
 
=== Step 2. Create the triggers ===
This step is to create the triggers that will initiate the scripts. The methods used to implement the trigger vary based on the Service Desk release.  
+
This step is to create the trigger that will initiate the script. The methods used to implement the trigger vary based on the Service Desk release.  
  
 
''For r11.x releases'' triggers are created via the [[Schema Designer]] utility. Add the following code as a [[Site-Defined Trigger]] to the  '''[[Act Log Table|alg (Request Activity Log)]]''' table.
 
''For r11.x releases'' triggers are created via the [[Schema Designer]] utility. Add the following code as a [[Site-Defined Trigger]] to the  '''[[Act Log Table|alg (Request Activity Log)]]''' table.
<source lang="javascript">POST_VALIDATE zmyscript1() 113 FILTER(type{-> 'LOG'});</source>
+
<source lang="javascript">POST_VALIDATE zemp_comment() 113 FILTER(type{-> 'LOG'});</source>
 
+
Add this code to the '''[[Call Req Table|cr (Request)]]''' table:
+
<source lang="javascript">POST_VALIDATE zmyscript2() 113 FILTER(string2 == 'LOG');</source>
+
  
  
Line 92: Line 63:
 
<source lang="javascript">alg {
 
<source lang="javascript">alg {
 
   TRIGGERS {
 
   TRIGGERS {
     POST_VALIDATE zmyscript1() 113 FILTER(type{-> 'LOG'});
+
     POST_VALIDATE zemp_comment() 113 FILTER(type{-> 'LOG'});
 
   };
 
   };
};
+
};</source>
 
+
cr {
+
  TRIGGERS {
+
    POST_VALIDATE zmyscript2() 113 FILTER(string2 == 'LOG');
+
  };
+
};
+
</source>
+
 
+
  
 
=== Step 3. Publish the Schema changes ===
 
=== Step 3. Publish the Schema changes ===
 
{{Publish Schema Change}}
 
{{Publish Schema Change}}

Latest revision as of 15:11, 6 November 2008

To make corrections or additions to this article, select the edit tab above.
To discuss or ask questions about this article, select the discussion tab above.

Overview

This article provides instructions for generating a notification when an Employee adds a comment to a Request, Incident, or Problem. It requires two sets of triggers and scripts, an event, and at least one Multiple Notification Macro.

If implementing this customization it is recommended that you disable the Log Comment Activity Notification.

Procedures

Step 1. Create the scripts

A script is created as an .spl file and placed in the $NX_ROOT/site/mods/majic directory. When the Service Desk service starts, the contents of the majic directory are processed and cached. You can use any naming scheme you like for your .spl file, but it is recommended that the file be preceded with a 'z' for easy identification as a custom file (eg zMyCompany.spl, zcr_scripts.spl, zMyScripts.spl).

This script is triggered on the Act_Log table and attaches an event to the ticket. The script assumes that the Employee Access Type is associated with the Employee Interface and that it is also set as the default Access Type. <source lang="javascript">alg::zemp_comment(...) { // The following IF STATEMENT assumes that 2405 is the id of the Employee Access Type // and that the Employee Access Type is the default. if (analyst.access_type == 2405 || is_null(analyst.access_type)) { object attached_events_table_record, group_leader; string z_evt; // Identify below the id of the event to attach. z_evt = "evt:400001";

if (!is_null(call_req_id.assignee)) { send_wait(0, top_object(), "get_co_group"); if (msg_error()) { logf(ERROR, "%s %s - %s", call_req_id.type.sym, call_req_id.ref_num, msg[0]); } group_leader = msg[0]; send_wait(0, top_object(), "call_attr", "atev", "get_new_dob", NULL, NULL, group_leader); if (msg_error()) { logf(ERROR, "%s %s - %s", call_req_id.type.sym, call_req_id.ref_num, msg[0]); } attached_events_table_record = msg[0]; attached_events_table_record.obj_id = call_req_id; attached_events_table_record.event_tmpl = z_evt; send_wait(0, group_leader, "checkin"); if (msg_error()) { logf(ERROR, "error attaching event %s to %s %s - %s", z_evt, call_req_id.type.sym, call_req_id.ref_num, msg[0]); } else { logf(SIGNIFICANT, "successfully attached event %s to %s %s", z_evt, call_req_id.type.sym, call_req_id.ref_num); } } } }</source>

Step 2. Create the triggers

This step is to create the trigger that will initiate the script. The methods used to implement the trigger vary based on the Service Desk release.

For r11.x releases triggers are created via the Schema Designer utility. Add the following code as a Site-Defined Trigger to the alg (Request Activity Log) table. <source lang="javascript">POST_VALIDATE zemp_comment() 113 FILTER(type{-> 'LOG'});</source>


For older releases triggers are made by creating a .mod file and placing it in the $NX_ROOT/site/mods/majic directory. Name the .mod anything you like, but it is recommended that it be preceded with a 'z'. <source lang="javascript">alg {

 TRIGGERS {
   POST_VALIDATE zemp_comment() 113 FILTER(type{-> 'LOG'});
 };

};</source>

Step 3. Publish the Schema changes

The methods used to publish schema changes vary based on the Service Desk release.

For r11.x releases, follow these steps:

  1. Save your Schema changes
  2. Stop the Service Desk service
  3. Run pdm_publish from a command line (Applicable if you made changes via WSP)
  4. Start the Service Desk service

For older releases recycle the Service Desk service.