Send Notification to CI's Attached Contacts

From SDU
Revision as of 14:49, 2 February 2009 by Gityerfix (Talk | contribs) (Notification to CI attached contact(s) moved to Send Notification to CI's Attached Contacts: Implemented standardize naming scheme)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 a notification to CI attached contact(s). Because severals CI can be attached on a changed, there is no native solution to send notification to all contacts attached to all CI attached to a change.

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"> chg::znotif_ci_cnt(...) { object nr_dob, nr_list, group_leader; int nr_count, i; string persid,chg_ref_num, wc, nr_retour,nr_id; persid = argv[3]; chg_ref_num = argv[6]; object cnt_dob, cnt_list; int cnt_count, j; string wc2,cnt_retour,cnt_id; string evt_mtitle, evt_mbody; evt_mtitle = format("CO '%s'", chg_ref_num); evt_mbody = format("CO'%s'", chg_ref_num); evt_mbody += format("blabla\n"); evt_mbody += format("blabla"); int evt_level; evt_level = 2; int trans_pt; trans_pt = 28;

//check if there is CI attached to the change wc = format("lpid = '%s' AND lattr = 'asset'", persid); send_wait(0, top_object(), "call_attr", "lrel1", "sync_fetch", "STATIC", wc, -1, 0); nr_list = msg[0]; nr_count = msg[1];

//For each CI we get the persid if (nr_count > 0) { for (i=0;i<nr_count;i++) {

send_wait(0, nr_list, "dob_by_index", "DEFAULT", i, i); nr_dob = msg[0]; send_wait (0, nr_dob, "get_attr_vals", 1, "rpid"); //CI UUID nr_retour = msg[3];


//for each CI we check if there is contact wc2 = format("rpid = '%s' AND rattr = 'cntref'", nr_retour); send_wait(0, top_object(), "call_attr", "lrel1", "sync_fetch", "STATIC", wc2, -1, 0); cnt_list = msg[0]; cnt_count = msg[1];

//if there is contact, send an email if (cnt_count > 0) { for (j=0;j<cnt_count;j++) { send_wait(0, cnt_list, "dob_by_index", "DEFAULT", j, j); cnt_dob = msg[0]; send_wait (0, cnt_dob, "get_attr_vals", 1, "lpid"); cnt_retour = msg[3]; cnt_id = substr(cnt_retour,sindex(cnt_retour,":")+1);

send(top_object(), "call_attr", "cnt", "notify_list", cnt_retour, evt_level, evt_mtitle, evt_mbody, "", trans_pt, persid, 0, 0);

} }

} } } </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 chg (Change Order) table.

POST_VALIDATE znotif_ci_cnt() 111 FILTER(EVENT("INSERT"));

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"> OBJECT chg {

 TRIGGERS {
   POST_VALIDATE znotif_ci_cnt() 111 FILTER(EVENT("INSERT"));
 };

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