Automatically Remove Attached Events

From SDU
Revision as of 14:04, 27 July 2008 by Gityerfix (Talk | contribs)

Jump to: navigation, search
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 having attached Events automatically removed.

Procedures

Step 1. Create the script

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).

<source lang="javascript">// Use 'cr' for Requests, Incidents & Problems, 'chg' for Changes, and 'iss' for Issues cr::zmyscript(...){ // Add additional event_tmpl arguments to the following line if needed. send_wait(0, top_object(), "call_attr", "atev", "sync_fetch", "STATIC", format("(event_tmpl = 'evt:400001' OR event_tmpl = 'evt:400002') AND obj_id = '%s'", persistent_id), -1, 0); if (msg_error()) { set_error(msg_error()); set_return_data(msg[0]); logf(ERROR, "Cannot get attached events for %s %s - %s", type.sym, ref_num, msg[0]); //logf(ERROR, "Cannot get attached events for Change Order %s - %s", chg_ref_num, msg[0]); //logf(ERROR, "Cannot get attached events for Issue %s - %s", ref_num, msg[0]); return; } else { logf(SIGNIFICANT, "Got atev list for %s %s", type.sym, ref_num); //logf(SIGNIFICANT, "Got atev list for Change Order %s", chg_ref_num); //logf(SIGNIFICANT, "Got atev list for Issue %s", ref_num); }

// Building attached event list from query results object atev_list; atev_list = msg[0]; int thelength; thelength = 0; thelength = msg[1]; if (msg_error()) { logf(ERROR, "error getting length of atev list for %s %s - %s", type.sym, ref_num, msg[0]); //logf(ERROR, "error getting length of atev list for Change Order %s - %s", chg_ref_num, msg[0]); //logf(ERROR, "error getting length of atev list for Issue %s - %s", ref_num, msg[0]); return; } else { logf(SIGNIFICANT, "event list length = %d for %s %s", thelength, type.sym, ref_num); //logf(SIGNIFICANT, "event list length = %d for Change Order %s", thelength, chg_ref_num); //logf(SIGNIFICANT, "event list length = %d for Issue %s", thelength, ref_num); }

// Canceling all events from list long index; int i; i=0; for (i; i<thelength; i++) { send_wait(0, atev_list, "dob_by_index", "DEFAULT", i, i); if (msg_error()) { logf(ERROR, "error getting dob_by_index for %s %s - %s", type.sym, ref_num, msg[0]); //logf(ERROR, "error getting dob_by_index for Change Order %s - %s", chg_ref_num, msg[0]); //logf(ERROR, "error getting dob_by_index for Issue %s - %s", ref_num, msg[0]); return; } object to_delete; to_delete = msg[0]; send_wait(0, to_delete, "cancel_me"); if (msg_error()) { logf(ERROR, "error deleting event %d for %s %s - %s", i, type.sym, ref_num, msg[0]); //logf(ERROR, "error deleting event %d for Change Order %s - %s", i, chg_ref_num, msg[0]); //logf(ERROR, "error deleting event %d for Issue %s - %s", i, ref_num, msg[0]); return; } else { logf(SIGNIFICANT, "successfully canceled event %d for %s %s", i, type.sym, ref_num); //logf(SIGNIFICANT, "successfully canceled event %d for Change Order %s", i, chg_ref_num); //logf(SIGNIFICANT, "successfully canceled event %d for Issue %s", i, ref_num); } } }</source>

The trigger that will be created in step 2 is the first level filtering. If you need further filtering then utilize an if statement in the spel code above.

Step 2. Create the trigger

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. In the examples to follow, the trigger is designed to fire if the Status is being changed to 'Resolved'. Use whatever filter you like for attaching your event.

For r11.x releases triggers are created via the Schema Designer utility. Simply add the following code as a Site-Defined Trigger to the cr (Request), chg (Change Order), or iss (Issue) table.

POST_VALIDATE zmyscript() 111 FILTER(EVENT("UPDATE") && status{'RE'->} && active != 0);

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">// Use OBJECT cr for Requests, Incidents & Problems // Use OBJECT chg for Change Orders // Use OBJECT iss for Issues OBJECT cr {

 TRIGGERS {
   POST_VALIDATE zmyscript() 111 FILTER(EVENT("UPDATE") && status{'RE'->} && active != 0);
 };

};</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.

See Also

Conditionally Attach an Event