TMACUL

http://www.servicedeskusers.com/Send_Survey_based_on_Variables

Blog Post created by TMACUL Champion on Jan 1, 2016

Send Survey based on Variables

From SDU

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 sending different Surveys based on specified variables..

Procedures

Step 1. Create Multiple Notification Macro

First step is to create a [Multiple Notification Macro] that will be attached to the ticket.

In the "Objects" tab, add the Affected End User.

Create a message similar to the following:

@{customer.combo_name} You recently contacted the helpdesk about the following issue: @{summary} Please click on the link below and let us know about your experience http://<server_name>/caisd/pdmweb.exe?OP=DO_SURVEY+SID=0+SVY_ID=<survey_template_id>+CNT_ID=@{customer}+CNTXT_PERSID=@{persistent_id}

Replace <server_name> with the name of your server and <survey_template_id> with the database id of your Survey Template.

Step 2. Create an Event

The next step is to create an event with no delay or repeat values. In the "Action Information" tab, add the [Multiple Notification Macro] created in Step 1 to the "actions on true" section.

Step 3. Add fields to Survey Template table

Add a field to the survey template table called "zcount" and a field to the contact record called "zlast_survey"

Step 4. 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.

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

POST_VALIDATE z_survey() 111 FILTER ( status { -> 'CL' }); 

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

OBJECT cr { TRIGGERS { POST_VALIDATE z_survey() 111 FILTER ( status { -> 'CL' }); }; };

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

cr::z_survey(...) { logf(SIGNIFICANT,"Trigger Worked"); object group_leader, zsurvey_tmpl; int do_survey, zreq_id, zsurvey_tpl_id; string errmsg, method, zcust_combo, zcust_org, zreq_persid, ztype; uuid zcust_id;   zcust_org = customer.organization; zreq_id = id; zcust_id = customer; zreq_persid = persistent_id; zcust_combo = customer.combo_name; ztype = type; method = "cr::z_beazer_survey() "; do_survey = 0;   //These are just here to log the values to make sure it works. can be removed later logf(SIGNIFICANT,"zcust_org=%s",zcust_org); logf(SIGNIFICANT,"zreq_id=%d",zreq_id); logf(SIGNIFICANT,"zcust_id=%s",zcust_id); logf(SIGNIFICANT,"zreq_persid=%s",zreq_persid); logf(SIGNIFICANT,"zcust_combo=%s",zcust_combo); logf(SIGNIFICANT,"ztype=%s",ztype);   //checks to see if customer is in a particular org and the ticket is an incident if ( zcust_org == '75D6AB63316EF149B1C3FA5A1390DA40' && ztype == "I") { //this is the survey template id for this org zsurvey_tpl_id = 9176281; do_survey = 1; } //checks to see if customer is a in a different org if ( zcust_org == 'D08CD8D4DA7C5C48BABB224B5089A93A') { //this is the template id for this org zsurvey_tpl_id = 9176283; do_survey = 1; } //if the org isn't named above,exit code if (do_survey == 0) { return; } //otherwise, get the survey template object.   send_wait(0, top_object(), "call_attr", "svy_tpl", "dob_by_id", 0, zsurvey_tpl_id, NULL, NULL); if ( msg_error()) { errmsg=format("Error in svy_tpl dob_by_id: '%s'",msg[0]); logf(ERROR,method+errmsg); set_return_data(errmsg); set_error(-1); return -1; }   object zsurvey_tmpl; zsurvey_tmpl=msg[0];   int zoldcount; int znewcount; int reset_count; int ztrk_flag; int zcycle; string zsurv_sym;   zoldcount = zsurvey_tmpl.zcount; ztrk_flag = zsurvey_tmpl.tracking_flag; zcycle = zsurvey_tmpl.submit_cycle; zsurv_sym = zsurvey_tmpl.sym; znewcount = zoldcount +1; reset_count = 0;   logf(SIGNIFICANT,"zoldcount=%d",zoldcount); logf(SIGNIFICANT,"ztrk_flag=%d",ztrk_flag); logf(SIGNIFICANT,"zcycle=%d",zcycle);   //if stricter rules is selected, this will pull the customer dob and check the last survey field if (ztrk_flag == 1){ //get the customer object send_wait(0, top_object(), "call_attr", "cnt", "dob_by_id", 0, zcust_id, NULL, NULL); if ( msg_error()) { errmsg=format("Error in cnt dob_by_id: '%s'",msg[0]); logf(ERROR,method+errmsg); set_return_data(errmsg); set_error(-1); return -1; } object zcustomer_obj; zcustomer_obj =msg[0];   date zlast_surv; date znow_time; duration ztimer;   if (is_null(zcustomer_obj.zlast_survey)) {zlast_surv = 0;} else {zlast_surv = zcustomer_obj.zlast_survey;} znow_time = now(); ztimer = znow_time-zlast_surv;   //if last survey was less than 90days ago, exit code if (ztimer < 7776000) { return; } } //now we need to check the cycle field. //get group leader so we can check out the svy tpl object and make changes send_wait(0, top_object(), "get_co_group"); if (msg_error()) { errmsg = format("%s get_co_group error '%s'", method, msg[0]); logf(ERROR, errmsg); set_return_data(errmsg); set_error(1); return -1; } group_leader = msg[0];   // check out the sry_tpl obj since we are updating it. send_wait(0, group_leader, "checkout", zsurvey_tmpl); if (msg_error()) { errmsg = format("checkout svy_tpl obj '%s' '%s'", method, msg[0]); logf(ERROR, errmsg); set_return_data(errmsg); set_error(1); return -1; }   //if the submit cycle number hasn't been reached. add one, check in  and exit code. if (znewcount < zcycle){ send_wait(0, zsurvey_tmpl, "call_attr", "zcount", "set_val", znewcount , "SURE_SET"); if ( msg_error()) { errmsg=format("Error setting zlast_survey: '%s'",msg[0]); logf(ERROR,method+errmsg); set_return_data(errmsg); set_error(-1); return -1; } //check the svy_tpl obj in send_wait(0, group_leader, "checkin"); if (msg_error()) { errmsg = format("checkin svy_tpl obj'%s' '%s'", method, msg[0]); logf(ERROR, errmsg); send_wait(0, group_leader, "uncheck"); set_return_data(errmsg); set_error(1); return -1; }; return; } //else,set the count back to zero and continue through the code else { send_wait(0, zsurvey_tmpl, "call_attr", "zcount", "set_val", reset_count , "SURE_SET"); if ( msg_error()) { errmsg=format("Error setting zlast_survey: '%s'",msg[0]); logf(ERROR,method+errmsg); set_return_data(errmsg); set_error(-1); return -1; } //check the svy_tpl obj in send_wait(0, group_leader, "checkin"); if (msg_error()) { errmsg = format("checkin svy_tpl obj'%s' '%s'", method, msg[0]); logf(ERROR, errmsg); send_wait(0, group_leader, "uncheck"); set_return_data(errmsg); set_error(1); return -1; } }   //this bit of code only fires if stricter rules if enforced //we get the customer obj, reset the last survey field to now. if (ztrk_flag == 1) { // get a group leader so can make changes to the customer obj send_wait(0, top_object(), "get_co_group"); if (msg_error()) { errmsg = format("%s get_co_group error '%s'", method, msg[0]); logf(ERROR, errmsg); set_return_data(errmsg); set_error(1); return -1; } group_leader = msg[0];   // check out the customer obj since we are updating it. send_wait(0, group_leader, "checkout", zcustomer_obj); if (msg_error()) { errmsg = format("checkout customer obj '%s' '%s'", method, msg[0]); logf(ERROR, errmsg); set_return_data(errmsg); set_error(1); return -1; } //set the zlast_survey field to now send_wait(0, zcustomer_obj, "call_attr", "zlast_survey", "set_val", znow_time , "SURE_SET"); if ( msg_error()) { errmsg=format("Error setting zlast_survey: '%s'",msg[0]); logf(ERROR,method+errmsg); set_return_data(errmsg); set_error(-1); return -1; } //check the customer obj in send_wait(0, group_leader, "checkin"); if (msg_error()) { errmsg = format("checkin customer obj'%s' '%s'", method, msg[0]); logf(ERROR, errmsg); send_wait(0, group_leader, "uncheck"); set_return_data(errmsg); set_error(1); return -1; }   //Now, create a surrvey tracking record. This prevents survey from being filled out more than once object survey_track_record;   send_wait(0, top_object(), "get_co_group");   if (msg_error()) { logf(ERROR, "Error getting group leader: error '%s'", msg[0]); return; }   group_leader = msg[0];   send_wait( 0, top_object(), "call_attr", "svytrk", "get_new_dob", NULL, NULL, group_leader);   if (msg_error()) { logf(ERROR, "Error creating new svytrk ob: error '%s'", msg[0]); return; }   survey_track_record = msg[0];   survey_track_record.tplid = zsurvey_tpl_id; survey_track_record.cntid = zcust_id; survey_track_record.object_type = "cr"; survey_track_record.object_id = zreq_id; survey_track_record.notif_dt = znow_time;   send_wait(0, group_leader, "checkin"); }     //regardless if stricter rules is selected or not, we need to add a survey sent activity record   object activity_log_record; string zalg_descr;   //this will format the description like the ones I saw in the activity log zalg_descr = format("Survey Request ('%s') sent to %s", zsurv_sym,zcust_combo);   send_wait(0, top_object(), "get_co_group");   if (msg_error()) { logf(ERROR, "Error getting group leader: error '%s'", msg[0]); return; }   group_leader = msg[0];   send_wait( 0, top_object(), "call_attr", "alg", "get_new_dob", NULL, NULL, group_leader);   if (msg_error()) { logf(ERROR, "Error creating new alg ob: error '%s'", msg[0]); return; }   activity_log_record = msg[0];   activity_log_record.call_req_id = zreq_persid; //this is the system ahd contact record id. activity_log_record.analyst = "793ED69B4E87A545BD8E911834D829FC"; activity_log_record.description = zalg_descr; activity_log_record.action_desc = zalg_descr; activity_log_record.type = "SRVY_SENT"; activity_log_record.internal = 0;   send_wait(0, group_leader, "checkin");   //finally, attach the event that sends out the message with the link object attached_events_table_record; send_wait(0, top_object(), "get_co_group");   if (msg_error()) { logf(ERROR, "zalglog () - Attach Event: error '%s'", msg[0]); return; }   group_leader = msg[0];   send_wait( 0, top_object(), "call_attr", "atev", "get_new_dob", NULL, NULL, group_leader);   if (msg_error()) { logf(ERROR, "error attaching event '%s'", msg[0]); return; } attached_events_table_record = msg[0]; attached_events_table_record.obj_id = zreq_persid; if (zsurvey_tpl_id == 9176281) //first org's survey from way up above { //evt:9452506 should be replaced with the event you created. I have two different  //surveys. If you only have one, remove the extra coding.  attached_events_table_record.event_tmpl = "evt:9452506"; } if (zsurvey_tpl_id == 9176283) //second org's survey { attached_events_table_record.event_tmpl = "evt:10224927"; }   send_wait(0, group_leader, "checkin");   }

Retrieved from "http://www.servicedeskusers.com/Send_Survey_based_on_Variables"

 

 

This page was last modified 05:27, 30 November 2010.  This page has been accessed 5,484 times.  Content is available under Attribution-Noncommercial-Share Alike 3.0 Unported.   Disclaimers         

Outcomes