Send Survey based on Variables

From SDU
Revision as of 16:41, 18 November 2008 by Mbraemer (Talk | contribs)

Jump to: navigation, search

--Mbraemer 09:40, 18 November 2008 (MST) 1. First you need to create a request mulitiple notification macro that will be attached to the request. In the "objects" tab, choose affected end user. This is the message template from mine. <server_name> should be changed to your url and <survey_template_id> should be changed to the id number of the survey you wish to send out. This will form the link that the user clicks: @{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} 2. Then add this to an event with no delay or repeat values. in the "Action information" tab, select the multi notification macro in the "actions on true" section. 3. I had to add a field to the survey template table called "zcount" and a field to the contact record called "zlast_survey" 4. Next, you want to create a .mod file with a trigger that will fire when you want the survey to be sent. I wanted mine to go out when the request was closed so mine looks like this: MODIFY cr POST_VALIDATE z_survey() 115 FILTER ( status { -> 'CL' }); 5. The rest will be in a .spl file. Mine is below and I have tried to comment it as much to where it makes sense. I have migrated to 11.2 so some of the fields are uuid fields and string fields instead of integer field. If you are still on 6.0, you will have to change this back to integer: cr::z_survey(...) { logf(SIGNIFICANT,"Trigger Worked"); string zcust_org; int zreq_id; uuid zcust_id; string zreq_persid; string zcust_combo; string ztype; string method; object group_leader; int do_survey; string errmsg; int zsurvey_tpl_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 stricker 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 stricker 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 stricker 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"); }