<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://greggsmith.net/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mbraemer</id>
		<title>SDU - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://greggsmith.net/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mbraemer"/>
		<link rel="alternate" type="text/html" href="http://greggsmith.net/wiki/index.php?title=Special:Contributions/Mbraemer"/>
		<updated>2026-09-23T07:55:37Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.26.1</generator>

	<entry>
		<id>http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4316</id>
		<title>Close attached incidents</title>
		<link rel="alternate" type="text/html" href="http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4316"/>
				<updated>2011-02-22T14:46:02Z</updated>
		
		<summary type="html">&lt;p&gt;Mbraemer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I was asked by the business folk in my company to come up with a way to close all attached incidents (just like the &amp;quot;Actions, Close All Children&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
'''STEP I:''' I started by creating the following object in WSP:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// Factory:   z_cr_close_att_inc&lt;br /&gt;
////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
OBJECT z_cr_close_att_inc {&lt;br /&gt;
  ATTRIBUTES z_cr_close_att_inc {&lt;br /&gt;
    description STRING 4000&lt;br /&gt;
      REQUIRED;&lt;br /&gt;
    owning_pr SREL pr&lt;br /&gt;
      REQUIRED;&lt;br /&gt;
    res_code SREL resocode;&lt;br /&gt;
    root_cause SREL rc;&lt;br /&gt;
    last_mod_dt DATE { ON_CI SET NOW; };&lt;br /&gt;
    last_mod_by SREL cnt { ON_CI SET USER;&lt;br /&gt;
                           ON_NEW DEFAULT USER; };&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  FACTORY z_cr_close_att_inc {&lt;br /&gt;
    STANDARD_LISTS {&lt;br /&gt;
      MLIST OFF;&lt;br /&gt;
      RLIST OFF;&lt;br /&gt;
    };&lt;br /&gt;
    REL_ATTR id;&lt;br /&gt;
    COMMON_NAME description;&lt;br /&gt;
  };&lt;br /&gt;
  TRIGGERS {&lt;br /&gt;
    POST_CI z_close_att_inc( persistent_id ) 1040 FILTER (EVENT(&amp;quot;INSERT&amp;quot;) );&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// End of object code&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only two required field here are the &amp;quot;owning_pr&amp;quot; (problem ticket srel) and the &amp;quot;description&amp;quot; (this becomes the solution. &lt;br /&gt;
The other fields are just fields in the incidents that we will update at the same time we close them. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''STEP II:''' Next, I created a detail form for the above object in WSP. I used the standard detail template but made the following changes:&lt;br /&gt;
                    1. Search for &amp;lt;PDM_MACRO NAME=dtlForm factory=&amp;quot;z_cr_close_att_inc&amp;gt; and change it to &amp;lt;PDM_MACRO NAME=dtlForm factory=&amp;quot;z_cr_close_att_inc&amp;quot; button=false&amp;gt;&lt;br /&gt;
                       (this keeps the default &amp;quot;Save, Cancel, Update&amp;quot; buttons from showing up).&lt;br /&gt;
                   2.  Next, I added my own buttons. This code codes in between the line above and the &amp;lt;PDM_MACRO NAME=dtlStart&amp;gt; tag:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
ImgBtnRow();&lt;br /&gt;
      ImgBtnCreate(&amp;quot;btn001&amp;quot;,&amp;quot;OK[k]&amp;quot;,&amp;quot;SaveAndClose();detailSave();&amp;quot;,true, 120);&lt;br /&gt;
      ImgBtnCreate(&amp;quot;btncncl&amp;quot;, &amp;quot;Cancel[n]&amp;quot;, &amp;quot;cancel_update('$prop.form_name_2','$args.id','show_main_detail.htmpl')&amp;quot;, true, 120);&lt;br /&gt;
      ImgBtnCreate(&amp;quot;btn003&amp;quot;, &amp;quot;Reset[R]&amp;quot;, &amp;quot;pdm_reset()&amp;quot;, true, 120);&lt;br /&gt;
ImgBtnEndRow();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
(the reason I did this is I wanted the detail from to close as soon as the &amp;quot;OK&amp;quot; button was clicked.)&lt;br /&gt;
&lt;br /&gt;
'''Step III:''' Next, I added the following code the the menubar_sd.htmpl right below the &amp;quot;Actions, Close All Children&amp;quot; link:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;PDM_OBJECT&amp;gt;&lt;br /&gt;
      if ( w.propFormName2 == &amp;quot;pr&amp;quot; ){&lt;br /&gt;
                 &amp;lt;PDM_MACRO name=menuItem label=&amp;quot;Close All Attached Incidents&amp;quot; function=&amp;quot;ahdtop.create_new('z_cr_close_att_inc',0,'','','PRESET=owning_pr:\&amp;quot; + w.argPersistentID + \&amp;quot; ')&amp;quot;&amp;gt;&lt;br /&gt;
                 }&lt;br /&gt;
 &amp;lt;/PDM_OBJECT&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
                (It will only show up if the ticket you are in is a Problem)&lt;br /&gt;
&lt;br /&gt;
'''Step IV:''' The Spel code. This code will load the fields in the detail_z_cr_close_att_inc.htmpl form into temp variables, parse through all attached incidents, update the fields, close the incident, and log a solution. At the very end, it will    delete the newly created z_cr_close_att_inc object  so you don't have to worry about it filling up your DB. I have commented the code throughout:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// MBRAEMER - 02/18/11 - Created - This code will all incidents where the problem field = the submitted problem ticket, &lt;br /&gt;
//                                  update the passed mandatory fields, then close-resolve the incidents. Then call a sleep,&lt;br /&gt;
//                                  then delete the z_cr_close_att_inc ticket.&lt;br /&gt;
//                       TRIGGER - POST_CI&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
z_cr_close_att_inc::z_close_att_inc(...) { &lt;br /&gt;
string errmsg, method, where_clause;&lt;br /&gt;
int count, i, debugging_f;&lt;br /&gt;
&lt;br /&gt;
method = &amp;quot;z_cr_close_att_inc::z_close_att_inc()&amp;quot;;&lt;br /&gt;
count = 0;&lt;br /&gt;
debugging_f = 1;&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;argv3 = %s&amp;quot;, argv[3]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//get the z_cr_close_att_inc object&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;z_cr_close_att_inc&amp;quot;, &amp;quot;dob_by_persid&amp;quot;, 0, argv[3], NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
	  errmsg=format(&amp;quot;Error in z_cr_close_att_inc dob_by_persid: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
      logf(ERROR,method+errmsg);&lt;br /&gt;
      set_return_data(errmsg);&lt;br /&gt;
      set_error(-1);&lt;br /&gt;
      return -1;&lt;br /&gt;
	    }&lt;br /&gt;
object this_crClAttIn;&lt;br /&gt;
this_crClAttIn = msg[0];&lt;br /&gt;
&lt;br /&gt;
//below will be the variables from the this_crClAttIn that will be passed to each incident being updated&lt;br /&gt;
string pr_persid, parent_description;&lt;br /&gt;
int rescd, this_rc;&lt;br /&gt;
&lt;br /&gt;
pr_persid = this_crClAttIn.owning_pr;&lt;br /&gt;
parent_description = this_crClAttIn.description;&lt;br /&gt;
&lt;br /&gt;
rescd = this_crClAttIn.res_code;&lt;br /&gt;
this_rc = this_crClAttIn.root_cause;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where_clause = format(&amp;quot;problem = '%s' AND active = 1&amp;quot;, pr_persid);&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;pr_persid = %s&amp;quot;, pr_persid);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;parent_description = %s&amp;quot;, parent_description);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;rescd = %d&amp;quot;, rescd);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;where_clause = %s&amp;quot;, where_clause);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
object attInc_domset;&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;cr&amp;quot;,&amp;quot;sync_fetch&amp;quot;, &amp;quot;DYNAMIC&amp;quot;, where_clause,  -1, 0);&lt;br /&gt;
    if (msg_error()) {&lt;br /&gt;
	errmsg=format(&amp;quot;cr sync_fetch: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
    logf(ERROR,method+errmsg);&lt;br /&gt;
    set_return_data(errmsg);&lt;br /&gt;
    set_error(-1);&lt;br /&gt;
    return -1;&lt;br /&gt;
     }&lt;br /&gt;
attInc_domset = msg[0];&lt;br /&gt;
count = msg[1];&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;count = %d&amp;quot;, count);&lt;br /&gt;
}&lt;br /&gt;
	&lt;br /&gt;
//if there are no attached incidents, get the heck outta dodge&lt;br /&gt;
if (count == 0){&lt;br /&gt;
	return;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
i=0;&lt;br /&gt;
&lt;br /&gt;
//cycle through all incidents in the above created domset&lt;br /&gt;
for (i; i&amp;lt;count; i++) { &lt;br /&gt;
	if ( debugging_f == 1) {&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;i = %s&amp;quot;, i);&lt;br /&gt;
		}&lt;br /&gt;
	send_wait(0, attInc_domset, &amp;quot;dob_by_index&amp;quot;, &amp;quot;DEFAULT&amp;quot;, 0, 0);&lt;br /&gt;
	if (msg_error()) {&lt;br /&gt;
		errmsg=format(&amp;quot;error getting dob_by_index: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
		logf(ERROR,method+errmsg);&lt;br /&gt;
		set_return_data(errmsg);&lt;br /&gt;
		set_error(-1);&lt;br /&gt;
		return -1;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
	object this_here_inc;&lt;br /&gt;
	this_here_inc = msg[0];&lt;br /&gt;
	&lt;br /&gt;
	//need to grab this incidents persid and current status for use later&lt;br /&gt;
	string this_inc_persid, this_status_cd;&lt;br /&gt;
	this_inc_persid = this_here_inc.persistent_id;&lt;br /&gt;
	this_status_cd = this_here_inc.status;&lt;br /&gt;
	&lt;br /&gt;
	if ( debugging_f == 1) {&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;this_inc_persid = %s&amp;quot;, this_inc_persid);&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;this_status_cd = %s&amp;quot;, this_status_cd);&lt;br /&gt;
		}&lt;br /&gt;
	&lt;br /&gt;
	//if the incident is not already closed-resolved, then update, close and log comment.&lt;br /&gt;
	if ( this_status_cd != 'CL'  ) {&lt;br /&gt;
		//check out the incident so you can update the mandatory fields&lt;br /&gt;
		object group_leader;&lt;br /&gt;
		send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error getting group_leader: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		group_leader = msg[0];&lt;br /&gt;
	&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, this_here_inc);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkout: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
	&lt;br /&gt;
		//Now set all of the necessary fields&lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;resolution_code&amp;quot;, &amp;quot;set_val&amp;quot;, rescd , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;rootcause&amp;quot;, &amp;quot;set_val&amp;quot;, this_rc , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
				&lt;br /&gt;
		//last, set status of ticket to closed-resolved&lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;status&amp;quot;, &amp;quot;set_val&amp;quot;, &amp;quot;CL&amp;quot; , &amp;quot;SURE_SET&amp;quot;);&lt;br /&gt;
			&lt;br /&gt;
		//now check back in&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkin: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}	&lt;br /&gt;
		&lt;br /&gt;
		//now, sleep and create a new activity to log the solution	&lt;br /&gt;
		sleep(3);&lt;br /&gt;
		send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error getting group_leader: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		group_leader = msg[0];	&lt;br /&gt;
	&lt;br /&gt;
		send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;alg&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error creating new record: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
		object new_alg_obj;&lt;br /&gt;
		new_alg_obj = msg[0];&lt;br /&gt;
	&lt;br /&gt;
		//set all of the attributes of the new alg object&lt;br /&gt;
		&lt;br /&gt;
		new_alg_obj.action_desc = &amp;quot;log solution text&amp;quot;;&lt;br /&gt;
		new_alg_obj.call_req_id = this_inc_persid;&lt;br /&gt;
		new_alg_obj.description = parent_description;&lt;br /&gt;
		new_alg_obj.time_spent = 0;&lt;br /&gt;
		new_alg_obj.type = &amp;quot;SOLN&amp;quot;;&lt;br /&gt;
	&lt;br /&gt;
		//now check the new object in&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkin&amp;quot;); &lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkin: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
	//exit loop	&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
//Now it's time to sleep and delete this object&lt;br /&gt;
sleep(3);&lt;br /&gt;
 &lt;br /&gt;
int this_id;&lt;br /&gt;
string delete_clause;&lt;br /&gt;
&lt;br /&gt;
this_id = this_crClAttIn.id;&lt;br /&gt;
delete_clause = format(&amp;quot;id=%d&amp;quot;, this_id);&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
	logf(SIGNIFICANT, &amp;quot;this_id = %d&amp;quot;, this_id);&lt;br /&gt;
	logf(SIGNIFICANT, &amp;quot;delete_clause = %s&amp;quot;, delete_clause);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;api&amp;quot;, &amp;quot;delete_wc&amp;quot;, &amp;quot;z_cr_close_att_inc&amp;quot;, delete_clause, NULL); &lt;br /&gt;
if (msg_error()) {&lt;br /&gt;
		errmsg=format(&amp;quot;error on delete: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
		logf(ERROR,method+errmsg);&lt;br /&gt;
		set_return_data(errmsg);&lt;br /&gt;
		set_error(-1);&lt;br /&gt;
		return -1;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// End of z_cr_close_att_inc::z_close_att_inc()&lt;br /&gt;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
That's pretty much it.&lt;/div&gt;</summary>
		<author><name>Mbraemer</name></author>	</entry>

	<entry>
		<id>http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4315</id>
		<title>Close attached incidents</title>
		<link rel="alternate" type="text/html" href="http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4315"/>
				<updated>2011-02-22T14:45:03Z</updated>
		
		<summary type="html">&lt;p&gt;Mbraemer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I was asked by the business folk in my company to come up with a way to close all attached incidents (just like the &amp;quot;Actions, Close All Children&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
'''STEP I:''' I started by creating the following object in WSP:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// Factory:   z_cr_close_att_inc&lt;br /&gt;
////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
OBJECT z_cr_close_att_inc {&lt;br /&gt;
  ATTRIBUTES z_cr_close_att_inc {&lt;br /&gt;
    description STRING 4000&lt;br /&gt;
      REQUIRED;&lt;br /&gt;
    owning_pr SREL pr&lt;br /&gt;
      REQUIRED;&lt;br /&gt;
    res_code SREL resocode;&lt;br /&gt;
    root_cause SREL rc;&lt;br /&gt;
    last_mod_dt DATE { ON_CI SET NOW; };&lt;br /&gt;
    last_mod_by SREL cnt { ON_CI SET USER;&lt;br /&gt;
                           ON_NEW DEFAULT USER; };&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  FACTORY z_cr_close_att_inc {&lt;br /&gt;
    STANDARD_LISTS {&lt;br /&gt;
      MLIST OFF;&lt;br /&gt;
      RLIST OFF;&lt;br /&gt;
    };&lt;br /&gt;
    REL_ATTR id;&lt;br /&gt;
    COMMON_NAME description;&lt;br /&gt;
  };&lt;br /&gt;
  TRIGGERS {&lt;br /&gt;
    POST_CI z_close_att_inc( persistent_id ) 1040 FILTER (EVENT(&amp;quot;INSERT&amp;quot;) );&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// End of object code&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only two required field here are the &amp;quot;owning_pr&amp;quot; (problem ticket srel) and the &amp;quot;description&amp;quot; (this becomes the solution. &lt;br /&gt;
The other fields are just fields in the incidents that we will update at the same time we close them. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''STEP II:''' Next, I created a detail form for the above object in WSP. I used the standard detail template but made the following changes:&lt;br /&gt;
                    1. Search for &amp;lt;PDM_MACRO NAME=dtlForm factory=&amp;quot;z_cr_close_att_inc&amp;gt; and change it to &amp;lt;PDM_MACRO NAME=dtlForm factory=&amp;quot;z_cr_close_att_inc&amp;quot; button=false&amp;gt;&lt;br /&gt;
                       (this keeps the default &amp;quot;Save, Cancel, Update&amp;quot; buttons from showing up).&lt;br /&gt;
                   2.  Next, I added my own buttons. This code codes in between the line above and the &amp;lt;PDM_MACRO NAME=dtlStart&amp;gt; tag:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
ImgBtnRow();&lt;br /&gt;
      ImgBtnCreate(&amp;quot;btn001&amp;quot;,&amp;quot;OK[k]&amp;quot;,&amp;quot;SaveAndClose();detailSave();&amp;quot;,true, 120);&lt;br /&gt;
      ImgBtnCreate(&amp;quot;btncncl&amp;quot;, &amp;quot;Cancel[n]&amp;quot;, &amp;quot;cancel_update('$prop.form_name_2','$args.id','show_main_detail.htmpl')&amp;quot;, true, 120);&lt;br /&gt;
      ImgBtnCreate(&amp;quot;btn003&amp;quot;, &amp;quot;Reset[R]&amp;quot;, &amp;quot;pdm_reset()&amp;quot;, true, 120);&lt;br /&gt;
ImgBtnEndRow();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
(the reason I did this is I wanted the detail from to close as soon as the &amp;quot;OK&amp;quot; button was clicked.)&lt;br /&gt;
&lt;br /&gt;
'''Step III:''' Next, I added the following code the the menubar_sd.htmpl right below the &amp;quot;Actions, Close All Children&amp;quot; link:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;PDM_OBJECT&amp;gt;&lt;br /&gt;
      if ( w.propFormName2 == &amp;quot;pr&amp;quot; ){&lt;br /&gt;
                 &amp;lt;PDM_MACRO name=menuItem label=&amp;quot;Close All Attached Incidents&amp;quot; function=&amp;quot;ahdtop.create_new('z_cr_close_att_inc',0,'','','PRESET=owning_pr:\&amp;quot; + w.argPersistentID + \&amp;quot; ')&amp;quot;&amp;gt;&lt;br /&gt;
                 }&lt;br /&gt;
 &amp;lt;/PDM_OBJECT&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
                (It will only show up if the ticket you are in is a Problem)&lt;br /&gt;
&lt;br /&gt;
'''Step IV:''' The Spel code. This code will load the fields in the detail_z_cr_close_att_inc.htmpl form into temp variables, parse through all attached incidents, update the fields, close the incident, and log a solution. At the very end, it will    delete the newly created z_cr_close_att_inc object  so you don't have to worry about it filling up your DB. I have commented the code throughout:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// MBRAEMER - 02/18/11 - Created - This code will all incidents where the problem field = the submitted problem ticket, &lt;br /&gt;
//                                  update the passed mandatory fields, then close-resolve the incidents. Then call a sleep,&lt;br /&gt;
//                                  then delete the z_cr_close_att_inc ticket.&lt;br /&gt;
//                       TRIGGER - POST_CI&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
z_cr_close_att_inc::z_close_att_inc(...) { &lt;br /&gt;
string errmsg, method, where_clause;&lt;br /&gt;
int count, i, debugging_f;&lt;br /&gt;
&lt;br /&gt;
method = &amp;quot;z_cr_close_att_inc::z_close_att_inc()&amp;quot;;&lt;br /&gt;
count = 0;&lt;br /&gt;
debugging_f = 1;&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;argv3 = %s&amp;quot;, argv[3]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//get the z_cr_close_att_inc object&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;z_cr_close_att_inc&amp;quot;, &amp;quot;dob_by_persid&amp;quot;, 0, argv[3], NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
	  errmsg=format(&amp;quot;Error in z_cr_close_att_inc dob_by_persid: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
      logf(ERROR,method+errmsg);&lt;br /&gt;
      set_return_data(errmsg);&lt;br /&gt;
      set_error(-1);&lt;br /&gt;
      return -1;&lt;br /&gt;
	    }&lt;br /&gt;
object this_crClAttIn;&lt;br /&gt;
this_crClAttIn = msg[0];&lt;br /&gt;
&lt;br /&gt;
//below will be the variables from the this_crClAttIn that will be passed to each incident being updated&lt;br /&gt;
string pr_persid, parent_description;&lt;br /&gt;
int rescd, this_rc;&lt;br /&gt;
&lt;br /&gt;
pr_persid = this_crClAttIn.owning_pr;&lt;br /&gt;
parent_description = this_crClAttIn.description;&lt;br /&gt;
&lt;br /&gt;
rescd = this_crClAttIn.res_code;&lt;br /&gt;
this_rc = this_crClAttIn.root_cause;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where_clause = format(&amp;quot;problem = '%s' AND active = 1&amp;quot;, pr_persid);&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;pr_persid = %s&amp;quot;, pr_persid);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;parent_description = %s&amp;quot;, parent_description);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;rescd = %d&amp;quot;, rescd);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;where_clause = %s&amp;quot;, where_clause);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
object attInc_domset;&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;cr&amp;quot;,&amp;quot;sync_fetch&amp;quot;, &amp;quot;DYNAMIC&amp;quot;, where_clause,  -1, 0);&lt;br /&gt;
    if (msg_error()) {&lt;br /&gt;
	errmsg=format(&amp;quot;cr sync_fetch: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
    logf(ERROR,method+errmsg);&lt;br /&gt;
    set_return_data(errmsg);&lt;br /&gt;
    set_error(-1);&lt;br /&gt;
    return -1;&lt;br /&gt;
     }&lt;br /&gt;
attInc_domset = msg[0];&lt;br /&gt;
count = msg[1];&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;count = %d&amp;quot;, count);&lt;br /&gt;
}&lt;br /&gt;
	&lt;br /&gt;
//if there are no attached incidents, get the heck outta dodge&lt;br /&gt;
if (count == 0){&lt;br /&gt;
	return;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
i=0;&lt;br /&gt;
&lt;br /&gt;
//cycle through all incidents in the above created domset&lt;br /&gt;
for (i; i&amp;lt;count; i++) { &lt;br /&gt;
	if ( debugging_f == 1) {&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;i = %s&amp;quot;, i);&lt;br /&gt;
		}&lt;br /&gt;
	send_wait(0, attInc_domset, &amp;quot;dob_by_index&amp;quot;, &amp;quot;DEFAULT&amp;quot;, 0, 0);&lt;br /&gt;
	if (msg_error()) {&lt;br /&gt;
		errmsg=format(&amp;quot;error getting dob_by_index: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
		logf(ERROR,method+errmsg);&lt;br /&gt;
		set_return_data(errmsg);&lt;br /&gt;
		set_error(-1);&lt;br /&gt;
		return -1;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
	object this_here_inc;&lt;br /&gt;
	this_here_inc = msg[0];&lt;br /&gt;
	&lt;br /&gt;
	//need to grab this incidents persid and current status for use later&lt;br /&gt;
	string this_inc_persid, this_status_cd;&lt;br /&gt;
	this_inc_persid = this_here_inc.persistent_id;&lt;br /&gt;
	this_status_cd = this_here_inc.status;&lt;br /&gt;
	&lt;br /&gt;
	if ( debugging_f == 1) {&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;this_inc_persid = %s&amp;quot;, this_inc_persid);&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;this_status_cd = %s&amp;quot;, this_status_cd);&lt;br /&gt;
		}&lt;br /&gt;
	&lt;br /&gt;
	//if the incident is not already closed-resolved, then update, close and log comment.&lt;br /&gt;
	if ( this_status_cd != 'CL'  ) {&lt;br /&gt;
		//check out the incident so you can update the mandatory fields&lt;br /&gt;
		object group_leader;&lt;br /&gt;
		send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error getting group_leader: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		group_leader = msg[0];&lt;br /&gt;
	&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, this_here_inc);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkout: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
	&lt;br /&gt;
		//Now set all of the necessary fields&lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;resolution_code&amp;quot;, &amp;quot;set_val&amp;quot;, rescd , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;rootcause&amp;quot;, &amp;quot;set_val&amp;quot;, this_rc , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
				&lt;br /&gt;
		//last, set status of ticket to closed-resolved&lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;status&amp;quot;, &amp;quot;set_val&amp;quot;, &amp;quot;CL&amp;quot; , &amp;quot;SURE_SET&amp;quot;);&lt;br /&gt;
			&lt;br /&gt;
		//now check back in&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkin: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}	&lt;br /&gt;
		&lt;br /&gt;
		//now, sleep and create a new activity to log the solution	&lt;br /&gt;
		sleep(3);&lt;br /&gt;
		send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error getting group_leader: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		group_leader = msg[0];	&lt;br /&gt;
	&lt;br /&gt;
		send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;alg&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error creating new record: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
		object new_alg_obj;&lt;br /&gt;
		new_alg_obj = msg[0];&lt;br /&gt;
	&lt;br /&gt;
		//set all of the attributes of the new alg object&lt;br /&gt;
		&lt;br /&gt;
		new_alg_obj.action_desc = &amp;quot;log solution text&amp;quot;;&lt;br /&gt;
		new_alg_obj.call_req_id = this_inc_persid;&lt;br /&gt;
		new_alg_obj.description = parent_description;&lt;br /&gt;
		new_alg_obj.time_spent = 0;&lt;br /&gt;
		new_alg_obj.type = &amp;quot;SOLN&amp;quot;;&lt;br /&gt;
	&lt;br /&gt;
		//now check the new object in&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkin&amp;quot;); &lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkin: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
	//exit loop	&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
//Now it's time to sleep and delete this object&lt;br /&gt;
sleep(3);&lt;br /&gt;
 &lt;br /&gt;
int this_id;&lt;br /&gt;
string delete_clause;&lt;br /&gt;
&lt;br /&gt;
this_id = this_crClAttIn.id;&lt;br /&gt;
delete_clause = format(&amp;quot;id=%d&amp;quot;, this_id);&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
	logf(SIGNIFICANT, &amp;quot;this_id = %d&amp;quot;, this_id);&lt;br /&gt;
	logf(SIGNIFICANT, &amp;quot;delete_clause = %s&amp;quot;, delete_clause);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;api&amp;quot;, &amp;quot;delete_wc&amp;quot;, &amp;quot;z_cr_close_att_inc&amp;quot;, delete_clause, NULL); &lt;br /&gt;
if (msg_error()) {&lt;br /&gt;
		errmsg=format(&amp;quot;error on delete: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
		logf(ERROR,method+errmsg);&lt;br /&gt;
		set_return_data(errmsg);&lt;br /&gt;
		set_error(-1);&lt;br /&gt;
		return -1;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// End of z_cr_close_att_inc::z_close_att_inc()&lt;br /&gt;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbraemer</name></author>	</entry>

	<entry>
		<id>http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4314</id>
		<title>Close attached incidents</title>
		<link rel="alternate" type="text/html" href="http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4314"/>
				<updated>2011-02-22T14:41:34Z</updated>
		
		<summary type="html">&lt;p&gt;Mbraemer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I was asked by the business folk in my company to come up with a way to close all attached incidents (just like the &amp;quot;Actions, Close All Children&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
'''STEP I:''' I started by creating the following object in WSP:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// Factory:   z_cr_close_att_inc&lt;br /&gt;
////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
OBJECT z_cr_close_att_inc {&lt;br /&gt;
  ATTRIBUTES z_cr_close_att_inc {&lt;br /&gt;
    description STRING 4000&lt;br /&gt;
      REQUIRED;&lt;br /&gt;
    owning_pr SREL pr&lt;br /&gt;
      REQUIRED;&lt;br /&gt;
    res_code SREL resocode;&lt;br /&gt;
    root_cause SREL rc;&lt;br /&gt;
    last_mod_dt DATE { ON_CI SET NOW; };&lt;br /&gt;
    last_mod_by SREL cnt { ON_CI SET USER;&lt;br /&gt;
                           ON_NEW DEFAULT USER; };&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  FACTORY z_cr_close_att_inc {&lt;br /&gt;
    STANDARD_LISTS {&lt;br /&gt;
      MLIST OFF;&lt;br /&gt;
      RLIST OFF;&lt;br /&gt;
    };&lt;br /&gt;
    REL_ATTR id;&lt;br /&gt;
    COMMON_NAME description;&lt;br /&gt;
  };&lt;br /&gt;
  TRIGGERS {&lt;br /&gt;
    POST_CI z_close_att_inc( persistent_id ) 1040 FILTER (EVENT(&amp;quot;INSERT&amp;quot;) );&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// End of object code&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only two required field here are the &amp;quot;owning_pr&amp;quot; (problem ticket srel) and the &amp;quot;description&amp;quot; (this becomes the solution. &lt;br /&gt;
The other fields are just fields in the incidents that we will update at the same time we close them. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''STEP II:''' Next, I created a detail form for the above object in WSP. I used the standard detail template but made the following changes:&lt;br /&gt;
                    1. Search for &amp;lt;PDM_MACRO NAME=dtlForm factory=&amp;quot;z_cr_close_att_inc&amp;gt; and change it to &amp;lt;PDM_MACRO NAME=dtlForm factory=&amp;quot;z_cr_close_att_inc&amp;quot; button=false&amp;gt;&lt;br /&gt;
                       (this keeps the default &amp;quot;Save, Cancel, Update&amp;quot; buttons from showing up).&lt;br /&gt;
                   2.  Next, I added my own buttons. This code codes in between the line above and the &amp;lt;PDM_MACRO NAME=dtlStart&amp;gt; tag:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
                         ImgBtnRow();&lt;br /&gt;
                         ImgBtnCreate(&amp;quot;btn001&amp;quot;,&amp;quot;OK[k]&amp;quot;,&amp;quot;SaveAndClose();detailSave();&amp;quot;,true, 120);&lt;br /&gt;
                         ImgBtnCreate(&amp;quot;btncncl&amp;quot;, &amp;quot;Cancel[n]&amp;quot;, &amp;quot;cancel_update('$prop.form_name_2','$args.id','show_main_detail.htmpl')&amp;quot;, true, 120);&lt;br /&gt;
                         ImgBtnCreate(&amp;quot;btn003&amp;quot;, &amp;quot;Reset[R]&amp;quot;, &amp;quot;pdm_reset()&amp;quot;, true, 120);&lt;br /&gt;
                         ImgBtnEndRow();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
                         (the reason I did this is I wanted the detail from to close as soon as the &amp;quot;OK&amp;quot; button was clicked.)&lt;br /&gt;
&lt;br /&gt;
'''Step III:''' Next, I added the following code the the menubar_sd.htmpl right below the &amp;quot;Actions, Close All Children&amp;quot; link:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;PDM_OBJECT&amp;gt;&lt;br /&gt;
&lt;br /&gt;
                  if ( w.propFormName2 == &amp;quot;pr&amp;quot; ){&lt;br /&gt;
&lt;br /&gt;
                 &amp;lt;PDM_MACRO name=menuItem label=&amp;quot;Close All Attached Incidents&amp;quot; function=&amp;quot;ahdtop.create_new('z_cr_close_att_inc',0,'','','PRESET=owning_pr:\&amp;quot; + w.argPersistentID + \&amp;quot; ')&amp;quot;&amp;gt;&lt;br /&gt;
                 }&lt;br /&gt;
                  &amp;lt;/PDM_OBJECT&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
                (It will only show up if the ticket you are in is a Problem)&lt;br /&gt;
&lt;br /&gt;
'''Step IV:''' The Spel code. This code will load the fields in the detail_z_cr_close_att_inc.htmpl form into temp variables, parse through all attached incidents, update the fields, close the incident, and log a solution. At the very end, it will    delete the newly created z_cr_close_att_inc object  so you don't have to worry about it filling up your DB. I have commented the code throughout:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// MBRAEMER - 02/18/11 - Created - This code will all incidents where the problem field = the submitted problem ticket, &lt;br /&gt;
//                                  update the passed mandatory fields, then close-resolve the incidents. Then call a sleep,&lt;br /&gt;
//                                  then delete the z_cr_close_att_inc ticket.&lt;br /&gt;
//                       TRIGGER - POST_CI&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
z_cr_close_att_inc::z_close_att_inc(...) { &lt;br /&gt;
string errmsg, method, where_clause;&lt;br /&gt;
int count, i, debugging_f;&lt;br /&gt;
&lt;br /&gt;
method = &amp;quot;z_cr_close_att_inc::z_close_att_inc()&amp;quot;;&lt;br /&gt;
count = 0;&lt;br /&gt;
debugging_f = 1;&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;argv3 = %s&amp;quot;, argv[3]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//get the z_cr_close_att_inc object&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;z_cr_close_att_inc&amp;quot;, &amp;quot;dob_by_persid&amp;quot;, 0, argv[3], NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
	  errmsg=format(&amp;quot;Error in z_cr_close_att_inc dob_by_persid: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
      logf(ERROR,method+errmsg);&lt;br /&gt;
      set_return_data(errmsg);&lt;br /&gt;
      set_error(-1);&lt;br /&gt;
      return -1;&lt;br /&gt;
	    }&lt;br /&gt;
object this_crClAttIn;&lt;br /&gt;
this_crClAttIn = msg[0];&lt;br /&gt;
&lt;br /&gt;
//below will be the variables from the this_crClAttIn that will be passed to each incident being updated&lt;br /&gt;
string pr_persid, parent_description;&lt;br /&gt;
int rescd, this_rc;&lt;br /&gt;
&lt;br /&gt;
pr_persid = this_crClAttIn.owning_pr;&lt;br /&gt;
parent_description = this_crClAttIn.description;&lt;br /&gt;
&lt;br /&gt;
rescd = this_crClAttIn.res_code;&lt;br /&gt;
this_rc = this_crClAttIn.root_cause;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where_clause = format(&amp;quot;problem = '%s' AND active = 1&amp;quot;, pr_persid);&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;pr_persid = %s&amp;quot;, pr_persid);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;parent_description = %s&amp;quot;, parent_description);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;rescd = %d&amp;quot;, rescd);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;where_clause = %s&amp;quot;, where_clause);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
object attInc_domset;&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;cr&amp;quot;,&amp;quot;sync_fetch&amp;quot;, &amp;quot;DYNAMIC&amp;quot;, where_clause,  -1, 0);&lt;br /&gt;
    if (msg_error()) {&lt;br /&gt;
	errmsg=format(&amp;quot;cr sync_fetch: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
    logf(ERROR,method+errmsg);&lt;br /&gt;
    set_return_data(errmsg);&lt;br /&gt;
    set_error(-1);&lt;br /&gt;
    return -1;&lt;br /&gt;
     }&lt;br /&gt;
attInc_domset = msg[0];&lt;br /&gt;
count = msg[1];&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;count = %d&amp;quot;, count);&lt;br /&gt;
}&lt;br /&gt;
	&lt;br /&gt;
//if there are no attached incidents, get the heck outta dodge&lt;br /&gt;
if (count == 0){&lt;br /&gt;
	return;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
i=0;&lt;br /&gt;
&lt;br /&gt;
//cycle through all incidents in the above created domset&lt;br /&gt;
for (i; i&amp;lt;count; i++) { &lt;br /&gt;
	if ( debugging_f == 1) {&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;i = %s&amp;quot;, i);&lt;br /&gt;
		}&lt;br /&gt;
	send_wait(0, attInc_domset, &amp;quot;dob_by_index&amp;quot;, &amp;quot;DEFAULT&amp;quot;, 0, 0);&lt;br /&gt;
	if (msg_error()) {&lt;br /&gt;
		errmsg=format(&amp;quot;error getting dob_by_index: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
		logf(ERROR,method+errmsg);&lt;br /&gt;
		set_return_data(errmsg);&lt;br /&gt;
		set_error(-1);&lt;br /&gt;
		return -1;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
	object this_here_inc;&lt;br /&gt;
	this_here_inc = msg[0];&lt;br /&gt;
	&lt;br /&gt;
	//need to grab this incidents persid and current status for use later&lt;br /&gt;
	string this_inc_persid, this_status_cd;&lt;br /&gt;
	this_inc_persid = this_here_inc.persistent_id;&lt;br /&gt;
	this_status_cd = this_here_inc.status;&lt;br /&gt;
	&lt;br /&gt;
	if ( debugging_f == 1) {&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;this_inc_persid = %s&amp;quot;, this_inc_persid);&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;this_status_cd = %s&amp;quot;, this_status_cd);&lt;br /&gt;
		}&lt;br /&gt;
	&lt;br /&gt;
	//if the incident is not already closed-resolved, then update, close and log comment.&lt;br /&gt;
	if ( this_status_cd != 'CL'  ) {&lt;br /&gt;
		//check out the incident so you can update the mandatory fields&lt;br /&gt;
		object group_leader;&lt;br /&gt;
		send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error getting group_leader: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		group_leader = msg[0];&lt;br /&gt;
	&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, this_here_inc);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkout: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
	&lt;br /&gt;
		//Now set all of the necessary fields&lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;resolution_code&amp;quot;, &amp;quot;set_val&amp;quot;, rescd , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;rootcause&amp;quot;, &amp;quot;set_val&amp;quot;, this_rc , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
				&lt;br /&gt;
		//last, set status of ticket to closed-resolved&lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;status&amp;quot;, &amp;quot;set_val&amp;quot;, &amp;quot;CL&amp;quot; , &amp;quot;SURE_SET&amp;quot;);&lt;br /&gt;
			&lt;br /&gt;
		//now check back in&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkin: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}	&lt;br /&gt;
		&lt;br /&gt;
		//now, sleep and create a new activity to log the solution	&lt;br /&gt;
		sleep(3);&lt;br /&gt;
		send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error getting group_leader: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		group_leader = msg[0];	&lt;br /&gt;
	&lt;br /&gt;
		send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;alg&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error creating new record: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
		object new_alg_obj;&lt;br /&gt;
		new_alg_obj = msg[0];&lt;br /&gt;
	&lt;br /&gt;
		//set all of the attributes of the new alg object&lt;br /&gt;
		&lt;br /&gt;
		new_alg_obj.action_desc = &amp;quot;log solution text&amp;quot;;&lt;br /&gt;
		new_alg_obj.call_req_id = this_inc_persid;&lt;br /&gt;
		new_alg_obj.description = parent_description;&lt;br /&gt;
		new_alg_obj.time_spent = 0;&lt;br /&gt;
		new_alg_obj.type = &amp;quot;SOLN&amp;quot;;&lt;br /&gt;
	&lt;br /&gt;
		//now check the new object in&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkin&amp;quot;); &lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkin: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
	//exit loop	&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
//Now it's time to sleep and delete this object&lt;br /&gt;
sleep(3);&lt;br /&gt;
 &lt;br /&gt;
int this_id;&lt;br /&gt;
string delete_clause;&lt;br /&gt;
&lt;br /&gt;
this_id = this_crClAttIn.id;&lt;br /&gt;
delete_clause = format(&amp;quot;id=%d&amp;quot;, this_id);&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
	logf(SIGNIFICANT, &amp;quot;this_id = %d&amp;quot;, this_id);&lt;br /&gt;
	logf(SIGNIFICANT, &amp;quot;delete_clause = %s&amp;quot;, delete_clause);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;api&amp;quot;, &amp;quot;delete_wc&amp;quot;, &amp;quot;z_cr_close_att_inc&amp;quot;, delete_clause, NULL); &lt;br /&gt;
if (msg_error()) {&lt;br /&gt;
		errmsg=format(&amp;quot;error on delete: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
		logf(ERROR,method+errmsg);&lt;br /&gt;
		set_return_data(errmsg);&lt;br /&gt;
		set_error(-1);&lt;br /&gt;
		return -1;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// End of z_cr_close_att_inc::z_close_att_inc()&lt;br /&gt;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbraemer</name></author>	</entry>

	<entry>
		<id>http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4313</id>
		<title>Close attached incidents</title>
		<link rel="alternate" type="text/html" href="http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4313"/>
				<updated>2011-02-22T14:40:18Z</updated>
		
		<summary type="html">&lt;p&gt;Mbraemer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I was asked by the business folk in my company to come up with a way to close all attached incidents (just like the &amp;quot;Actions, Close All Children&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
'''STEP I:''' I started by creating the following object in WSP:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// Factory:   z_cr_close_att_inc&lt;br /&gt;
////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
OBJECT z_cr_close_att_inc {&lt;br /&gt;
  ATTRIBUTES z_cr_close_att_inc {&lt;br /&gt;
    description STRING 4000&lt;br /&gt;
      REQUIRED;&lt;br /&gt;
    owning_pr SREL pr&lt;br /&gt;
      REQUIRED;&lt;br /&gt;
    res_code SREL resocode;&lt;br /&gt;
    root_cause SREL rc;&lt;br /&gt;
    last_mod_dt DATE { ON_CI SET NOW; };&lt;br /&gt;
    last_mod_by SREL cnt { ON_CI SET USER;&lt;br /&gt;
                           ON_NEW DEFAULT USER; };&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  FACTORY z_cr_close_att_inc {&lt;br /&gt;
    STANDARD_LISTS {&lt;br /&gt;
      MLIST OFF;&lt;br /&gt;
      RLIST OFF;&lt;br /&gt;
    };&lt;br /&gt;
    REL_ATTR id;&lt;br /&gt;
    COMMON_NAME description;&lt;br /&gt;
  };&lt;br /&gt;
  TRIGGERS {&lt;br /&gt;
    POST_CI z_close_att_inc( persistent_id ) 1040 FILTER (EVENT(&amp;quot;INSERT&amp;quot;) );&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// End of object code&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only two required field here are the &amp;quot;owning_pr&amp;quot; (problem ticket srel) and the &amp;quot;description&amp;quot; (this becomes the solution. &lt;br /&gt;
The other fields are just fields in the incidents that we will update at the same time we close them. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''STEP II:''' Next, I created a detail form for the above object in WSP. I used the standard detail template but made the following changes:&lt;br /&gt;
                    1. Search for &amp;lt;PDM_MACRO NAME=dtlForm factory=&amp;quot;z_cr_close_att_inc&amp;gt; and change it to &amp;lt;PDM_MACRO NAME=dtlForm factory=&amp;quot;z_cr_close_att_inc&amp;quot; button=false&amp;gt;&lt;br /&gt;
                       (this keeps the default &amp;quot;Save, Cancel, Update&amp;quot; buttons from showing up).&lt;br /&gt;
                   2.  Next, I added my own buttons. This code codes in between the line above and the &amp;lt;PDM_MACRO NAME=dtlStart&amp;gt; tag:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
                         ImgBtnRow();&lt;br /&gt;
                         ImgBtnCreate(&amp;quot;btn001&amp;quot;,&amp;quot;OK[k]&amp;quot;,&amp;quot;SaveAndClose();detailSave();&amp;quot;,true, 120);&lt;br /&gt;
                         ImgBtnCreate(&amp;quot;btncncl&amp;quot;, &amp;quot;Cancel[n]&amp;quot;, &amp;quot;cancel_update('$prop.form_name_2','$args.id','show_main_detail.htmpl')&amp;quot;, true, 120);&lt;br /&gt;
                         ImgBtnCreate(&amp;quot;btn003&amp;quot;, &amp;quot;Reset[R]&amp;quot;, &amp;quot;pdm_reset()&amp;quot;, true, 120);&lt;br /&gt;
                         ImgBtnEndRow();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
                         (the reason I did this is I wanted the detail from to close as soon as the &amp;quot;OK&amp;quot; button was clicked.)&lt;br /&gt;
&lt;br /&gt;
'''Step III:''' Next, I added the following code the the menubar_sd.htmpl right below the &amp;quot;Actions, Close All Children&amp;quot; link:&lt;br /&gt;
                  &amp;lt;PDM_OBJECT&amp;gt;&lt;br /&gt;
&lt;br /&gt;
                  if ( w.propFormName2 == &amp;quot;pr&amp;quot; ){&lt;br /&gt;
&lt;br /&gt;
                 &amp;lt;PDM_MACRO name=menuItem label=&amp;quot;Close All Attached Incidents&amp;quot; function=&amp;quot;ahdtop.create_new('z_cr_close_att_inc',0,'','','PRESET=owning_pr:\&amp;quot; + w.argPersistentID + \&amp;quot; ')&amp;quot;&amp;gt;&lt;br /&gt;
                 }&lt;br /&gt;
                  &amp;lt;/PDM_OBJECT&amp;gt;&lt;br /&gt;
                (It will only show up if the ticket you are in is a Problem)&lt;br /&gt;
&lt;br /&gt;
'''Step IV:''' The Spel code. This code will load the fields in the detail_z_cr_close_att_inc.htmpl form into temp variables, parse through all attached incidents, update the fields, close the incident, and log a solution. At the very end, it will    delete the newly created z_cr_close_att_inc object  so you don't have to worry about it filling up your DB. I have commented the code throughout:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// MBRAEMER - 02/18/11 - Created - This code will all incidents where the problem field = the submitted problem ticket, &lt;br /&gt;
//                                  update the passed mandatory fields, then close-resolve the incidents. Then call a sleep,&lt;br /&gt;
//                                  then delete the z_cr_close_att_inc ticket.&lt;br /&gt;
//                       TRIGGER - POST_CI&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
z_cr_close_att_inc::z_close_att_inc(...) { &lt;br /&gt;
string errmsg, method, where_clause;&lt;br /&gt;
int count, i, debugging_f;&lt;br /&gt;
&lt;br /&gt;
method = &amp;quot;z_cr_close_att_inc::z_close_att_inc()&amp;quot;;&lt;br /&gt;
count = 0;&lt;br /&gt;
debugging_f = 1;&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;argv3 = %s&amp;quot;, argv[3]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//get the z_cr_close_att_inc object&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;z_cr_close_att_inc&amp;quot;, &amp;quot;dob_by_persid&amp;quot;, 0, argv[3], NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
	  errmsg=format(&amp;quot;Error in z_cr_close_att_inc dob_by_persid: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
      logf(ERROR,method+errmsg);&lt;br /&gt;
      set_return_data(errmsg);&lt;br /&gt;
      set_error(-1);&lt;br /&gt;
      return -1;&lt;br /&gt;
	    }&lt;br /&gt;
object this_crClAttIn;&lt;br /&gt;
this_crClAttIn = msg[0];&lt;br /&gt;
&lt;br /&gt;
//below will be the variables from the this_crClAttIn that will be passed to each incident being updated&lt;br /&gt;
string pr_persid, parent_description;&lt;br /&gt;
int rescd, this_rc;&lt;br /&gt;
&lt;br /&gt;
pr_persid = this_crClAttIn.owning_pr;&lt;br /&gt;
parent_description = this_crClAttIn.description;&lt;br /&gt;
&lt;br /&gt;
rescd = this_crClAttIn.res_code;&lt;br /&gt;
this_rc = this_crClAttIn.root_cause;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where_clause = format(&amp;quot;problem = '%s' AND active = 1&amp;quot;, pr_persid);&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;pr_persid = %s&amp;quot;, pr_persid);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;parent_description = %s&amp;quot;, parent_description);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;rescd = %d&amp;quot;, rescd);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;where_clause = %s&amp;quot;, where_clause);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
object attInc_domset;&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;cr&amp;quot;,&amp;quot;sync_fetch&amp;quot;, &amp;quot;DYNAMIC&amp;quot;, where_clause,  -1, 0);&lt;br /&gt;
    if (msg_error()) {&lt;br /&gt;
	errmsg=format(&amp;quot;cr sync_fetch: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
    logf(ERROR,method+errmsg);&lt;br /&gt;
    set_return_data(errmsg);&lt;br /&gt;
    set_error(-1);&lt;br /&gt;
    return -1;&lt;br /&gt;
     }&lt;br /&gt;
attInc_domset = msg[0];&lt;br /&gt;
count = msg[1];&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;count = %d&amp;quot;, count);&lt;br /&gt;
}&lt;br /&gt;
	&lt;br /&gt;
//if there are no attached incidents, get the heck outta dodge&lt;br /&gt;
if (count == 0){&lt;br /&gt;
	return;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
i=0;&lt;br /&gt;
&lt;br /&gt;
//cycle through all incidents in the above created domset&lt;br /&gt;
for (i; i&amp;lt;count; i++) { &lt;br /&gt;
	if ( debugging_f == 1) {&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;i = %s&amp;quot;, i);&lt;br /&gt;
		}&lt;br /&gt;
	send_wait(0, attInc_domset, &amp;quot;dob_by_index&amp;quot;, &amp;quot;DEFAULT&amp;quot;, 0, 0);&lt;br /&gt;
	if (msg_error()) {&lt;br /&gt;
		errmsg=format(&amp;quot;error getting dob_by_index: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
		logf(ERROR,method+errmsg);&lt;br /&gt;
		set_return_data(errmsg);&lt;br /&gt;
		set_error(-1);&lt;br /&gt;
		return -1;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
	object this_here_inc;&lt;br /&gt;
	this_here_inc = msg[0];&lt;br /&gt;
	&lt;br /&gt;
	//need to grab this incidents persid and current status for use later&lt;br /&gt;
	string this_inc_persid, this_status_cd;&lt;br /&gt;
	this_inc_persid = this_here_inc.persistent_id;&lt;br /&gt;
	this_status_cd = this_here_inc.status;&lt;br /&gt;
	&lt;br /&gt;
	if ( debugging_f == 1) {&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;this_inc_persid = %s&amp;quot;, this_inc_persid);&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;this_status_cd = %s&amp;quot;, this_status_cd);&lt;br /&gt;
		}&lt;br /&gt;
	&lt;br /&gt;
	//if the incident is not already closed-resolved, then update, close and log comment.&lt;br /&gt;
	if ( this_status_cd != 'CL'  ) {&lt;br /&gt;
		//check out the incident so you can update the mandatory fields&lt;br /&gt;
		object group_leader;&lt;br /&gt;
		send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error getting group_leader: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		group_leader = msg[0];&lt;br /&gt;
	&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, this_here_inc);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkout: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
	&lt;br /&gt;
		//Now set all of the necessary fields&lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;resolution_code&amp;quot;, &amp;quot;set_val&amp;quot;, rescd , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;rootcause&amp;quot;, &amp;quot;set_val&amp;quot;, this_rc , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
				&lt;br /&gt;
		//last, set status of ticket to closed-resolved&lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;status&amp;quot;, &amp;quot;set_val&amp;quot;, &amp;quot;CL&amp;quot; , &amp;quot;SURE_SET&amp;quot;);&lt;br /&gt;
			&lt;br /&gt;
		//now check back in&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkin: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}	&lt;br /&gt;
		&lt;br /&gt;
		//now, sleep and create a new activity to log the solution	&lt;br /&gt;
		sleep(3);&lt;br /&gt;
		send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error getting group_leader: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		group_leader = msg[0];	&lt;br /&gt;
	&lt;br /&gt;
		send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;alg&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error creating new record: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
		object new_alg_obj;&lt;br /&gt;
		new_alg_obj = msg[0];&lt;br /&gt;
	&lt;br /&gt;
		//set all of the attributes of the new alg object&lt;br /&gt;
		&lt;br /&gt;
		new_alg_obj.action_desc = &amp;quot;log solution text&amp;quot;;&lt;br /&gt;
		new_alg_obj.call_req_id = this_inc_persid;&lt;br /&gt;
		new_alg_obj.description = parent_description;&lt;br /&gt;
		new_alg_obj.time_spent = 0;&lt;br /&gt;
		new_alg_obj.type = &amp;quot;SOLN&amp;quot;;&lt;br /&gt;
	&lt;br /&gt;
		//now check the new object in&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkin&amp;quot;); &lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkin: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
	//exit loop	&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
//Now it's time to sleep and delete this object&lt;br /&gt;
sleep(3);&lt;br /&gt;
 &lt;br /&gt;
int this_id;&lt;br /&gt;
string delete_clause;&lt;br /&gt;
&lt;br /&gt;
this_id = this_crClAttIn.id;&lt;br /&gt;
delete_clause = format(&amp;quot;id=%d&amp;quot;, this_id);&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
	logf(SIGNIFICANT, &amp;quot;this_id = %d&amp;quot;, this_id);&lt;br /&gt;
	logf(SIGNIFICANT, &amp;quot;delete_clause = %s&amp;quot;, delete_clause);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;api&amp;quot;, &amp;quot;delete_wc&amp;quot;, &amp;quot;z_cr_close_att_inc&amp;quot;, delete_clause, NULL); &lt;br /&gt;
if (msg_error()) {&lt;br /&gt;
		errmsg=format(&amp;quot;error on delete: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
		logf(ERROR,method+errmsg);&lt;br /&gt;
		set_return_data(errmsg);&lt;br /&gt;
		set_error(-1);&lt;br /&gt;
		return -1;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// End of z_cr_close_att_inc::z_close_att_inc()&lt;br /&gt;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbraemer</name></author>	</entry>

	<entry>
		<id>http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4312</id>
		<title>Close attached incidents</title>
		<link rel="alternate" type="text/html" href="http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4312"/>
				<updated>2011-02-22T14:38:10Z</updated>
		
		<summary type="html">&lt;p&gt;Mbraemer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I was asked by the business folk in my company to come up with a way to close all attached incidents (just like the &amp;quot;Actions, Close All Children&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
'''STEP I:''' I started by creating the following object in WSP:&lt;br /&gt;
&lt;br /&gt;
////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// Factory:   z_cr_close_att_inc&lt;br /&gt;
////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
OBJECT z_cr_close_att_inc {&lt;br /&gt;
  ATTRIBUTES z_cr_close_att_inc {&lt;br /&gt;
    description STRING 4000&lt;br /&gt;
      REQUIRED;&lt;br /&gt;
    owning_pr SREL pr&lt;br /&gt;
      REQUIRED;&lt;br /&gt;
    res_code SREL resocode;&lt;br /&gt;
    root_cause SREL rc;&lt;br /&gt;
    last_mod_dt DATE { ON_CI SET NOW; };&lt;br /&gt;
    last_mod_by SREL cnt { ON_CI SET USER;&lt;br /&gt;
                           ON_NEW DEFAULT USER; };&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  FACTORY z_cr_close_att_inc {&lt;br /&gt;
    STANDARD_LISTS {&lt;br /&gt;
      MLIST OFF;&lt;br /&gt;
      RLIST OFF;&lt;br /&gt;
    };&lt;br /&gt;
    REL_ATTR id;&lt;br /&gt;
    COMMON_NAME description;&lt;br /&gt;
  };&lt;br /&gt;
  TRIGGERS {&lt;br /&gt;
    POST_CI z_close_att_inc( persistent_id ) 1040 FILTER (EVENT(&amp;quot;INSERT&amp;quot;) );&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// End of object code&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
The only two required field here are the &amp;quot;owning_pr&amp;quot; (problem ticket srel) and the &amp;quot;description&amp;quot; (this becomes the solution. &lt;br /&gt;
The other fields are just fields in the incidents that we will update at the same time we close them. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''STEP II:''' Next, I created a detail form for the above object in WSP. I used the standard detail template but made the following changes:&lt;br /&gt;
                    1. Search for &amp;lt;PDM_MACRO NAME=dtlForm factory=&amp;quot;z_cr_close_att_inc&amp;gt; and change it to &amp;lt;PDM_MACRO NAME=dtlForm factory=&amp;quot;z_cr_close_att_inc&amp;quot; button=false&amp;gt;&lt;br /&gt;
                       (this keeps the default &amp;quot;Save, Cancel, Update&amp;quot; buttons from showing up).&lt;br /&gt;
                   2.  Next, I added my own buttons. This code codes in between the line above and the &amp;lt;PDM_MACRO NAME=dtlStart&amp;gt; tag:&lt;br /&gt;
                         ImgBtnRow();&lt;br /&gt;
                         ImgBtnCreate(&amp;quot;btn001&amp;quot;,&amp;quot;OK[k]&amp;quot;,&amp;quot;SaveAndClose();detailSave();&amp;quot;,true, 120);&lt;br /&gt;
                         ImgBtnCreate(&amp;quot;btncncl&amp;quot;, &amp;quot;Cancel[n]&amp;quot;, &amp;quot;cancel_update('$prop.form_name_2','$args.id','show_main_detail.htmpl')&amp;quot;, true, 120);&lt;br /&gt;
                         ImgBtnCreate(&amp;quot;btn003&amp;quot;, &amp;quot;Reset[R]&amp;quot;, &amp;quot;pdm_reset()&amp;quot;, true, 120);&lt;br /&gt;
                         ImgBtnEndRow();&lt;br /&gt;
                         (the reason I did this is I wanted the detail from to close as soon as the &amp;quot;OK&amp;quot; button was clicked.)&lt;br /&gt;
&lt;br /&gt;
'''Step III:''' Next, I added the following code the the menubar_sd.htmpl right below the &amp;quot;Actions, Close All Children&amp;quot; link:&lt;br /&gt;
                  &amp;lt;PDM_OBJECT&amp;gt;&lt;br /&gt;
&lt;br /&gt;
                  if ( w.propFormName2 == &amp;quot;pr&amp;quot; ){&lt;br /&gt;
&lt;br /&gt;
                 &amp;lt;PDM_MACRO name=menuItem label=&amp;quot;Close All Attached Incidents&amp;quot; function=&amp;quot;ahdtop.create_new('z_cr_close_att_inc',0,'','','PRESET=owning_pr:\&amp;quot; + w.argPersistentID + \&amp;quot; ')&amp;quot;&amp;gt;&lt;br /&gt;
                 }&lt;br /&gt;
                  &amp;lt;/PDM_OBJECT&amp;gt;&lt;br /&gt;
                (It will only show up if the ticket you are in is a Problem)&lt;br /&gt;
&lt;br /&gt;
'''Step IV:''' The Spel code. This code will load the fields in the detail_z_cr_close_att_inc.htmpl form into temp variables, parse through all attached incidents, update the fields, close the incident, and log a solution. At the very end, it will    delete the newly created z_cr_close_att_inc object  so you don't have to worry about it filling up your DB. I have commented the code throughout:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// MBRAEMER - 02/18/11 - Created - This code will all incidents where the problem field = the submitted problem ticket, &lt;br /&gt;
//                                  update the passed mandatory fields, then close-resolve the incidents. Then call a sleep,&lt;br /&gt;
//                                  then delete the z_cr_close_att_inc ticket.&lt;br /&gt;
//                       TRIGGER - POST_CI&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
z_cr_close_att_inc::z_close_att_inc(...) { &lt;br /&gt;
string errmsg, method, where_clause;&lt;br /&gt;
int count, i, debugging_f;&lt;br /&gt;
&lt;br /&gt;
method = &amp;quot;z_cr_close_att_inc::z_close_att_inc()&amp;quot;;&lt;br /&gt;
count = 0;&lt;br /&gt;
debugging_f = 1;&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;argv3 = %s&amp;quot;, argv[3]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//get the z_cr_close_att_inc object&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;z_cr_close_att_inc&amp;quot;, &amp;quot;dob_by_persid&amp;quot;, 0, argv[3], NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
	  errmsg=format(&amp;quot;Error in z_cr_close_att_inc dob_by_persid: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
      logf(ERROR,method+errmsg);&lt;br /&gt;
      set_return_data(errmsg);&lt;br /&gt;
      set_error(-1);&lt;br /&gt;
      return -1;&lt;br /&gt;
	    }&lt;br /&gt;
object this_crClAttIn;&lt;br /&gt;
this_crClAttIn = msg[0];&lt;br /&gt;
&lt;br /&gt;
//below will be the variables from the this_crClAttIn that will be passed to each incident being updated&lt;br /&gt;
string pr_persid, parent_description;&lt;br /&gt;
int rescd, this_rc;&lt;br /&gt;
&lt;br /&gt;
pr_persid = this_crClAttIn.owning_pr;&lt;br /&gt;
parent_description = this_crClAttIn.description;&lt;br /&gt;
&lt;br /&gt;
rescd = this_crClAttIn.res_code;&lt;br /&gt;
this_rc = this_crClAttIn.root_cause;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where_clause = format(&amp;quot;problem = '%s' AND active = 1&amp;quot;, pr_persid);&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;pr_persid = %s&amp;quot;, pr_persid);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;parent_description = %s&amp;quot;, parent_description);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;rescd = %d&amp;quot;, rescd);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;where_clause = %s&amp;quot;, where_clause);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
object attInc_domset;&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;cr&amp;quot;,&amp;quot;sync_fetch&amp;quot;, &amp;quot;DYNAMIC&amp;quot;, where_clause,  -1, 0);&lt;br /&gt;
    if (msg_error()) {&lt;br /&gt;
	errmsg=format(&amp;quot;cr sync_fetch: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
    logf(ERROR,method+errmsg);&lt;br /&gt;
    set_return_data(errmsg);&lt;br /&gt;
    set_error(-1);&lt;br /&gt;
    return -1;&lt;br /&gt;
     }&lt;br /&gt;
attInc_domset = msg[0];&lt;br /&gt;
count = msg[1];&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;count = %d&amp;quot;, count);&lt;br /&gt;
}&lt;br /&gt;
	&lt;br /&gt;
//if there are no attached incidents, get the heck outta dodge&lt;br /&gt;
if (count == 0){&lt;br /&gt;
	return;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
i=0;&lt;br /&gt;
&lt;br /&gt;
//cycle through all incidents in the above created domset&lt;br /&gt;
for (i; i&amp;lt;count; i++) { &lt;br /&gt;
	if ( debugging_f == 1) {&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;i = %s&amp;quot;, i);&lt;br /&gt;
		}&lt;br /&gt;
	send_wait(0, attInc_domset, &amp;quot;dob_by_index&amp;quot;, &amp;quot;DEFAULT&amp;quot;, 0, 0);&lt;br /&gt;
	if (msg_error()) {&lt;br /&gt;
		errmsg=format(&amp;quot;error getting dob_by_index: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
		logf(ERROR,method+errmsg);&lt;br /&gt;
		set_return_data(errmsg);&lt;br /&gt;
		set_error(-1);&lt;br /&gt;
		return -1;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
	object this_here_inc;&lt;br /&gt;
	this_here_inc = msg[0];&lt;br /&gt;
	&lt;br /&gt;
	//need to grab this incidents persid and current status for use later&lt;br /&gt;
	string this_inc_persid, this_status_cd;&lt;br /&gt;
	this_inc_persid = this_here_inc.persistent_id;&lt;br /&gt;
	this_status_cd = this_here_inc.status;&lt;br /&gt;
	&lt;br /&gt;
	if ( debugging_f == 1) {&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;this_inc_persid = %s&amp;quot;, this_inc_persid);&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;this_status_cd = %s&amp;quot;, this_status_cd);&lt;br /&gt;
		}&lt;br /&gt;
	&lt;br /&gt;
	//if the incident is not already closed-resolved, then update, close and log comment.&lt;br /&gt;
	if ( this_status_cd != 'CL'  ) {&lt;br /&gt;
		//check out the incident so you can update the mandatory fields&lt;br /&gt;
		object group_leader;&lt;br /&gt;
		send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error getting group_leader: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		group_leader = msg[0];&lt;br /&gt;
	&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, this_here_inc);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkout: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
	&lt;br /&gt;
		//Now set all of the necessary fields&lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;resolution_code&amp;quot;, &amp;quot;set_val&amp;quot;, rescd , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;rootcause&amp;quot;, &amp;quot;set_val&amp;quot;, this_rc , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
				&lt;br /&gt;
		//last, set status of ticket to closed-resolved&lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;status&amp;quot;, &amp;quot;set_val&amp;quot;, &amp;quot;CL&amp;quot; , &amp;quot;SURE_SET&amp;quot;);&lt;br /&gt;
			&lt;br /&gt;
		//now check back in&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkin: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}	&lt;br /&gt;
		&lt;br /&gt;
		//now, sleep and create a new activity to log the solution	&lt;br /&gt;
		sleep(3);&lt;br /&gt;
		send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error getting group_leader: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		group_leader = msg[0];	&lt;br /&gt;
	&lt;br /&gt;
		send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;alg&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error creating new record: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
		object new_alg_obj;&lt;br /&gt;
		new_alg_obj = msg[0];&lt;br /&gt;
	&lt;br /&gt;
		//set all of the attributes of the new alg object&lt;br /&gt;
		&lt;br /&gt;
		new_alg_obj.action_desc = &amp;quot;log solution text&amp;quot;;&lt;br /&gt;
		new_alg_obj.call_req_id = this_inc_persid;&lt;br /&gt;
		new_alg_obj.description = parent_description;&lt;br /&gt;
		new_alg_obj.time_spent = 0;&lt;br /&gt;
		new_alg_obj.type = &amp;quot;SOLN&amp;quot;;&lt;br /&gt;
	&lt;br /&gt;
		//now check the new object in&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkin&amp;quot;); &lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkin: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
	//exit loop	&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
//Now it's time to sleep and delete this object&lt;br /&gt;
sleep(3);&lt;br /&gt;
 &lt;br /&gt;
int this_id;&lt;br /&gt;
string delete_clause;&lt;br /&gt;
&lt;br /&gt;
this_id = this_crClAttIn.id;&lt;br /&gt;
delete_clause = format(&amp;quot;id=%d&amp;quot;, this_id);&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
	logf(SIGNIFICANT, &amp;quot;this_id = %d&amp;quot;, this_id);&lt;br /&gt;
	logf(SIGNIFICANT, &amp;quot;delete_clause = %s&amp;quot;, delete_clause);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;api&amp;quot;, &amp;quot;delete_wc&amp;quot;, &amp;quot;z_cr_close_att_inc&amp;quot;, delete_clause, NULL); &lt;br /&gt;
if (msg_error()) {&lt;br /&gt;
		errmsg=format(&amp;quot;error on delete: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
		logf(ERROR,method+errmsg);&lt;br /&gt;
		set_return_data(errmsg);&lt;br /&gt;
		set_error(-1);&lt;br /&gt;
		return -1;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// End of z_cr_close_att_inc::z_close_att_inc()&lt;br /&gt;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbraemer</name></author>	</entry>

	<entry>
		<id>http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4311</id>
		<title>Close attached incidents</title>
		<link rel="alternate" type="text/html" href="http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4311"/>
				<updated>2011-02-22T14:37:30Z</updated>
		
		<summary type="html">&lt;p&gt;Mbraemer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I was asked by the business folk in my company to come up with a way to close all attached incidents (just like the &amp;quot;Actions, Close All Children&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
'''STEP I:''' I started by creating the following object in WSP:&lt;br /&gt;
&lt;br /&gt;
////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// Factory:   z_cr_close_att_inc&lt;br /&gt;
////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
OBJECT z_cr_close_att_inc {&lt;br /&gt;
  ATTRIBUTES z_cr_close_att_inc {&lt;br /&gt;
    description STRING 4000&lt;br /&gt;
      REQUIRED;&lt;br /&gt;
    owning_pr SREL pr&lt;br /&gt;
      REQUIRED;&lt;br /&gt;
    res_code SREL resocode;&lt;br /&gt;
    root_cause SREL rc;&lt;br /&gt;
    last_mod_dt DATE { ON_CI SET NOW; };&lt;br /&gt;
    last_mod_by SREL cnt { ON_CI SET USER;&lt;br /&gt;
                           ON_NEW DEFAULT USER; };&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  FACTORY z_cr_close_att_inc {&lt;br /&gt;
    STANDARD_LISTS {&lt;br /&gt;
      MLIST OFF;&lt;br /&gt;
      RLIST OFF;&lt;br /&gt;
    };&lt;br /&gt;
    REL_ATTR id;&lt;br /&gt;
    COMMON_NAME description;&lt;br /&gt;
  };&lt;br /&gt;
  TRIGGERS {&lt;br /&gt;
    POST_CI z_close_att_inc( persistent_id ) 1040 FILTER (EVENT(&amp;quot;INSERT&amp;quot;) );&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// End of object code&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
The only two required field here are the &amp;quot;owning_pr&amp;quot; (problem ticket srel) and the &amp;quot;description&amp;quot; (this becomes the solution. &lt;br /&gt;
The other fields are just fields in the incidents that we will update at the same time we close them. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''STEP II:''' Next, I created a detail form for the above object in WSP. I used the standard detail template but made the following changes:&lt;br /&gt;
                    1. Search for &amp;lt;PDM_MACRO NAME=dtlForm factory=&amp;quot;z_cr_close_att_inc&amp;gt; and change it to &amp;lt;PDM_MACRO NAME=dtlForm factory=&amp;quot;z_cr_close_att_inc&amp;quot; button=false&amp;gt;&lt;br /&gt;
                       (this keeps the default &amp;quot;Save, Cancel, Update&amp;quot; buttons from showing up).&lt;br /&gt;
                   2.  Next, I added my own buttons. This code codes in between the line above and the &amp;lt;PDM_MACRO NAME=dtlStart&amp;gt; tag:&lt;br /&gt;
                         ImgBtnRow();&lt;br /&gt;
                         ImgBtnCreate(&amp;quot;btn001&amp;quot;,&amp;quot;OK[k]&amp;quot;,&amp;quot;SaveAndClose();detailSave();&amp;quot;,true, 120);&lt;br /&gt;
                         ImgBtnCreate(&amp;quot;btncncl&amp;quot;, &amp;quot;Cancel[n]&amp;quot;, &amp;quot;cancel_update('$prop.form_name_2','$args.id','show_main_detail.htmpl')&amp;quot;, true, 120);&lt;br /&gt;
                         ImgBtnCreate(&amp;quot;btn003&amp;quot;, &amp;quot;Reset[R]&amp;quot;, &amp;quot;pdm_reset()&amp;quot;, true, 120);&lt;br /&gt;
                         ImgBtnEndRow();&lt;br /&gt;
                         (the reason I did this is I wanted the detail from to close as soon as the &amp;quot;OK&amp;quot; button was clicked.)&lt;br /&gt;
&lt;br /&gt;
'''Step III:''' Next, I added the following code the the menubar_sd.htmpl right below the &amp;quot;Actions, Close All Children&amp;quot; link:&lt;br /&gt;
                  &amp;lt;PDM_OBJECT&amp;gt;&lt;br /&gt;
&lt;br /&gt;
                  if ( w.propFormName2 == &amp;quot;pr&amp;quot; ){&lt;br /&gt;
&lt;br /&gt;
                 &amp;lt;PDM_MACRO name=menuItem label=&amp;quot;Close All Attached Incidents&amp;quot; function=&amp;quot;ahdtop.create_new('z_cr_close_att_inc',0,'','','PRESET=owning_pr:\&amp;quot; + w.argPersistentID + \&amp;quot; ')&amp;quot;&amp;gt;&lt;br /&gt;
                 }&lt;br /&gt;
                  &amp;lt;/PDM_OBJECT&amp;gt;&lt;br /&gt;
                (It will only show up if the ticket you are in is a Problem)&lt;br /&gt;
&lt;br /&gt;
'''Step IV:''' The Spel code. This code will load the fields in the detail_z_cr_close_att_inc.htmpl form into temp variables, parse through all attached incidents, update the fields, close the incident, and log a solution. At the very end, it will    delete the newly created z_cr_close_att_inc object  so you don't have to worry about it filling up your DB. I have commented the code throughout:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;spel&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// MBRAEMER - 02/18/11 - Created - This code will all incidents where the problem field = the submitted problem ticket, &lt;br /&gt;
//                                  update the passed mandatory fields, then close-resolve the incidents. Then call a sleep,&lt;br /&gt;
//                                  then delete the z_cr_close_att_inc ticket.&lt;br /&gt;
//                       TRIGGER - POST_CI&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
z_cr_close_att_inc::z_close_att_inc(...) { &lt;br /&gt;
string errmsg, method, where_clause;&lt;br /&gt;
int count, i, debugging_f;&lt;br /&gt;
&lt;br /&gt;
method = &amp;quot;z_cr_close_att_inc::z_close_att_inc()&amp;quot;;&lt;br /&gt;
count = 0;&lt;br /&gt;
debugging_f = 1;&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;argv3 = %s&amp;quot;, argv[3]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//get the z_cr_close_att_inc object&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;z_cr_close_att_inc&amp;quot;, &amp;quot;dob_by_persid&amp;quot;, 0, argv[3], NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
	  errmsg=format(&amp;quot;Error in z_cr_close_att_inc dob_by_persid: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
      logf(ERROR,method+errmsg);&lt;br /&gt;
      set_return_data(errmsg);&lt;br /&gt;
      set_error(-1);&lt;br /&gt;
      return -1;&lt;br /&gt;
	    }&lt;br /&gt;
object this_crClAttIn;&lt;br /&gt;
this_crClAttIn = msg[0];&lt;br /&gt;
&lt;br /&gt;
//below will be the variables from the this_crClAttIn that will be passed to each incident being updated&lt;br /&gt;
string pr_persid, parent_description;&lt;br /&gt;
int rescd, this_rc;&lt;br /&gt;
&lt;br /&gt;
pr_persid = this_crClAttIn.owning_pr;&lt;br /&gt;
parent_description = this_crClAttIn.description;&lt;br /&gt;
&lt;br /&gt;
rescd = this_crClAttIn.res_code;&lt;br /&gt;
this_rc = this_crClAttIn.root_cause;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where_clause = format(&amp;quot;problem = '%s' AND active = 1&amp;quot;, pr_persid);&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;pr_persid = %s&amp;quot;, pr_persid);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;parent_description = %s&amp;quot;, parent_description);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;rescd = %d&amp;quot;, rescd);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;where_clause = %s&amp;quot;, where_clause);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
object attInc_domset;&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;cr&amp;quot;,&amp;quot;sync_fetch&amp;quot;, &amp;quot;DYNAMIC&amp;quot;, where_clause,  -1, 0);&lt;br /&gt;
    if (msg_error()) {&lt;br /&gt;
	errmsg=format(&amp;quot;cr sync_fetch: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
    logf(ERROR,method+errmsg);&lt;br /&gt;
    set_return_data(errmsg);&lt;br /&gt;
    set_error(-1);&lt;br /&gt;
    return -1;&lt;br /&gt;
     }&lt;br /&gt;
attInc_domset = msg[0];&lt;br /&gt;
count = msg[1];&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;count = %d&amp;quot;, count);&lt;br /&gt;
}&lt;br /&gt;
	&lt;br /&gt;
//if there are no attached incidents, get the heck outta dodge&lt;br /&gt;
if (count == 0){&lt;br /&gt;
	return;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
i=0;&lt;br /&gt;
&lt;br /&gt;
//cycle through all incidents in the above created domset&lt;br /&gt;
for (i; i&amp;lt;count; i++) { &lt;br /&gt;
	if ( debugging_f == 1) {&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;i = %s&amp;quot;, i);&lt;br /&gt;
		}&lt;br /&gt;
	send_wait(0, attInc_domset, &amp;quot;dob_by_index&amp;quot;, &amp;quot;DEFAULT&amp;quot;, 0, 0);&lt;br /&gt;
	if (msg_error()) {&lt;br /&gt;
		errmsg=format(&amp;quot;error getting dob_by_index: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
		logf(ERROR,method+errmsg);&lt;br /&gt;
		set_return_data(errmsg);&lt;br /&gt;
		set_error(-1);&lt;br /&gt;
		return -1;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
	object this_here_inc;&lt;br /&gt;
	this_here_inc = msg[0];&lt;br /&gt;
	&lt;br /&gt;
	//need to grab this incidents persid and current status for use later&lt;br /&gt;
	string this_inc_persid, this_status_cd;&lt;br /&gt;
	this_inc_persid = this_here_inc.persistent_id;&lt;br /&gt;
	this_status_cd = this_here_inc.status;&lt;br /&gt;
	&lt;br /&gt;
	if ( debugging_f == 1) {&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;this_inc_persid = %s&amp;quot;, this_inc_persid);&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;this_status_cd = %s&amp;quot;, this_status_cd);&lt;br /&gt;
		}&lt;br /&gt;
	&lt;br /&gt;
	//if the incident is not already closed-resolved, then update, close and log comment.&lt;br /&gt;
	if ( this_status_cd != 'CL'  ) {&lt;br /&gt;
		//check out the incident so you can update the mandatory fields&lt;br /&gt;
		object group_leader;&lt;br /&gt;
		send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error getting group_leader: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		group_leader = msg[0];&lt;br /&gt;
	&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, this_here_inc);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkout: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
	&lt;br /&gt;
		//Now set all of the necessary fields&lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;resolution_code&amp;quot;, &amp;quot;set_val&amp;quot;, rescd , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;rootcause&amp;quot;, &amp;quot;set_val&amp;quot;, this_rc , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
				&lt;br /&gt;
		//last, set status of ticket to closed-resolved&lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;status&amp;quot;, &amp;quot;set_val&amp;quot;, &amp;quot;CL&amp;quot; , &amp;quot;SURE_SET&amp;quot;);&lt;br /&gt;
			&lt;br /&gt;
		//now check back in&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkin: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}	&lt;br /&gt;
		&lt;br /&gt;
		//now, sleep and create a new activity to log the solution	&lt;br /&gt;
		sleep(3);&lt;br /&gt;
		send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error getting group_leader: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		group_leader = msg[0];	&lt;br /&gt;
	&lt;br /&gt;
		send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;alg&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error creating new record: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
		object new_alg_obj;&lt;br /&gt;
		new_alg_obj = msg[0];&lt;br /&gt;
	&lt;br /&gt;
		//set all of the attributes of the new alg object&lt;br /&gt;
		&lt;br /&gt;
		new_alg_obj.action_desc = &amp;quot;log solution text&amp;quot;;&lt;br /&gt;
		new_alg_obj.call_req_id = this_inc_persid;&lt;br /&gt;
		new_alg_obj.description = parent_description;&lt;br /&gt;
		new_alg_obj.time_spent = 0;&lt;br /&gt;
		new_alg_obj.type = &amp;quot;SOLN&amp;quot;;&lt;br /&gt;
	&lt;br /&gt;
		//now check the new object in&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkin&amp;quot;); &lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkin: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
	//exit loop	&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
//Now it's time to sleep and delete this object&lt;br /&gt;
sleep(3);&lt;br /&gt;
 &lt;br /&gt;
int this_id;&lt;br /&gt;
string delete_clause;&lt;br /&gt;
&lt;br /&gt;
this_id = this_crClAttIn.id;&lt;br /&gt;
delete_clause = format(&amp;quot;id=%d&amp;quot;, this_id);&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
	logf(SIGNIFICANT, &amp;quot;this_id = %d&amp;quot;, this_id);&lt;br /&gt;
	logf(SIGNIFICANT, &amp;quot;delete_clause = %s&amp;quot;, delete_clause);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;api&amp;quot;, &amp;quot;delete_wc&amp;quot;, &amp;quot;z_cr_close_att_inc&amp;quot;, delete_clause, NULL); &lt;br /&gt;
if (msg_error()) {&lt;br /&gt;
		errmsg=format(&amp;quot;error on delete: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
		logf(ERROR,method+errmsg);&lt;br /&gt;
		set_return_data(errmsg);&lt;br /&gt;
		set_error(-1);&lt;br /&gt;
		return -1;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// End of z_cr_close_att_inc::z_close_att_inc()&lt;br /&gt;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbraemer</name></author>	</entry>

	<entry>
		<id>http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4310</id>
		<title>Close attached incidents</title>
		<link rel="alternate" type="text/html" href="http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4310"/>
				<updated>2011-02-22T14:33:55Z</updated>
		
		<summary type="html">&lt;p&gt;Mbraemer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I was asked by the business folk in my company to come up with a way to close all attached incidents (just like the &amp;quot;Actions, Close All Children&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
'''STEP I:''' I started by creating the following object in WSP:&lt;br /&gt;
&lt;br /&gt;
////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// Factory:   z_cr_close_att_inc&lt;br /&gt;
////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
OBJECT z_cr_close_att_inc {&lt;br /&gt;
  ATTRIBUTES z_cr_close_att_inc {&lt;br /&gt;
    description STRING 4000&lt;br /&gt;
      REQUIRED;&lt;br /&gt;
    owning_pr SREL pr&lt;br /&gt;
      REQUIRED;&lt;br /&gt;
    res_code SREL resocode;&lt;br /&gt;
    root_cause SREL rc;&lt;br /&gt;
    last_mod_dt DATE { ON_CI SET NOW; };&lt;br /&gt;
    last_mod_by SREL cnt { ON_CI SET USER;&lt;br /&gt;
                           ON_NEW DEFAULT USER; };&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  FACTORY z_cr_close_att_inc {&lt;br /&gt;
    STANDARD_LISTS {&lt;br /&gt;
      MLIST OFF;&lt;br /&gt;
      RLIST OFF;&lt;br /&gt;
    };&lt;br /&gt;
    REL_ATTR id;&lt;br /&gt;
    COMMON_NAME description;&lt;br /&gt;
  };&lt;br /&gt;
  TRIGGERS {&lt;br /&gt;
    POST_CI z_close_att_inc( persistent_id ) 1040 FILTER (EVENT(&amp;quot;INSERT&amp;quot;) );&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// End of object code&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
The only two required field here are the &amp;quot;owning_pr&amp;quot; (problem ticket srel) and the &amp;quot;description&amp;quot; (this becomes the solution. &lt;br /&gt;
The other fields are just fields in the incidents that we will update at the same time we close them. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''STEP II:''' Next, I created a detail form for the above object in WSP. I used the standard detail template but made the following changes:&lt;br /&gt;
                    1. Search for &amp;lt;PDM_MACRO NAME=dtlForm factory=&amp;quot;z_cr_close_att_inc&amp;gt; and change it to &amp;lt;PDM_MACRO NAME=dtlForm factory=&amp;quot;z_cr_close_att_inc&amp;quot; button=false&amp;gt;&lt;br /&gt;
                       (this keeps the default &amp;quot;Save, Cancel, Update&amp;quot; buttons from showing up).&lt;br /&gt;
                   2.  Next, I added my own buttons. This code codes in between the line above and the &amp;lt;PDM_MACRO NAME=dtlStart&amp;gt; tag:&lt;br /&gt;
                         ImgBtnRow();&lt;br /&gt;
                         ImgBtnCreate(&amp;quot;btn001&amp;quot;,&amp;quot;OK[k]&amp;quot;,&amp;quot;SaveAndClose();detailSave();&amp;quot;,true, 120);&lt;br /&gt;
                         ImgBtnCreate(&amp;quot;btncncl&amp;quot;, &amp;quot;Cancel[n]&amp;quot;, &amp;quot;cancel_update('$prop.form_name_2','$args.id','show_main_detail.htmpl')&amp;quot;, true, 120);&lt;br /&gt;
                         ImgBtnCreate(&amp;quot;btn003&amp;quot;, &amp;quot;Reset[R]&amp;quot;, &amp;quot;pdm_reset()&amp;quot;, true, 120);&lt;br /&gt;
                         ImgBtnEndRow();&lt;br /&gt;
                         (the reason I did this is I wanted the detail from to close as soon as the &amp;quot;OK&amp;quot; button was clicked.)&lt;br /&gt;
&lt;br /&gt;
'''Step III:''' Next, I added the following code the the menubar_sd.htmpl right below the &amp;quot;Actions, Close All Children&amp;quot; link:&lt;br /&gt;
                  &amp;lt;PDM_OBJECT&amp;gt;&lt;br /&gt;
&lt;br /&gt;
                  if ( w.propFormName2 == &amp;quot;pr&amp;quot; ){&lt;br /&gt;
&lt;br /&gt;
                 &amp;lt;PDM_MACRO name=menuItem label=&amp;quot;Close All Attached Incidents&amp;quot; function=&amp;quot;ahdtop.create_new('z_cr_close_att_inc',0,'','','PRESET=owning_pr:\&amp;quot; + w.argPersistentID + \&amp;quot; ')&amp;quot;&amp;gt;&lt;br /&gt;
                 }&lt;br /&gt;
                  &amp;lt;/PDM_OBJECT&amp;gt;&lt;br /&gt;
                (It will only show up if the ticket you are in is a Problem)&lt;br /&gt;
&lt;br /&gt;
'''Step IV:''' The Spel code. This code will load the fields in the detail_z_cr_close_att_inc.htmpl form into temp variables, parse through all attached incidents, update the fields, close the incident, and log a solution. At the very end, it will    delete the newly created z_cr_close_att_inc object  so you don't have to worry about it filling up your DB. I have commented the code throughout:&lt;br /&gt;
&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// MBRAEMER - 02/18/11 - Created - This code will all incidents where the problem field = the submitted problem ticket, &lt;br /&gt;
//                                  update the passed mandatory fields, then close-resolve the incidents. Then call a sleep,&lt;br /&gt;
//                                  then delete the z_cr_close_att_inc ticket.&lt;br /&gt;
//                       TRIGGER - POST_CI&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
z_cr_close_att_inc::z_close_att_inc(...) { &lt;br /&gt;
string errmsg, method, where_clause;&lt;br /&gt;
int count, i, debugging_f;&lt;br /&gt;
&lt;br /&gt;
method = &amp;quot;z_cr_close_att_inc::z_close_att_inc()&amp;quot;;&lt;br /&gt;
count = 0;&lt;br /&gt;
debugging_f = 1;&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;argv3 = %s&amp;quot;, argv[3]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//get the z_cr_close_att_inc object&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;z_cr_close_att_inc&amp;quot;, &amp;quot;dob_by_persid&amp;quot;, 0, argv[3], NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
	  errmsg=format(&amp;quot;Error in z_cr_close_att_inc dob_by_persid: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
      logf(ERROR,method+errmsg);&lt;br /&gt;
      set_return_data(errmsg);&lt;br /&gt;
      set_error(-1);&lt;br /&gt;
      return -1;&lt;br /&gt;
	    }&lt;br /&gt;
object this_crClAttIn;&lt;br /&gt;
this_crClAttIn = msg[0];&lt;br /&gt;
&lt;br /&gt;
//below will be the variables from the this_crClAttIn that will be passed to each incident being updated&lt;br /&gt;
string pr_persid, parent_description;&lt;br /&gt;
int rescd, this_rc;&lt;br /&gt;
&lt;br /&gt;
pr_persid = this_crClAttIn.owning_pr;&lt;br /&gt;
parent_description = this_crClAttIn.description;&lt;br /&gt;
&lt;br /&gt;
rescd = this_crClAttIn.res_code;&lt;br /&gt;
this_rc = this_crClAttIn.root_cause;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
where_clause = format(&amp;quot;problem = '%s' AND active = 1&amp;quot;, pr_persid);&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;pr_persid = %s&amp;quot;, pr_persid);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;parent_description = %s&amp;quot;, parent_description);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;rescd = %d&amp;quot;, rescd);&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;where_clause = %s&amp;quot;, where_clause);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
object attInc_domset;&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;cr&amp;quot;,&amp;quot;sync_fetch&amp;quot;, &amp;quot;DYNAMIC&amp;quot;, where_clause,  -1, 0);&lt;br /&gt;
    if (msg_error()) {&lt;br /&gt;
	errmsg=format(&amp;quot;cr sync_fetch: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
    logf(ERROR,method+errmsg);&lt;br /&gt;
    set_return_data(errmsg);&lt;br /&gt;
    set_error(-1);&lt;br /&gt;
    return -1;&lt;br /&gt;
     }&lt;br /&gt;
attInc_domset = msg[0];&lt;br /&gt;
count = msg[1];&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
logf(SIGNIFICANT, &amp;quot;count = %d&amp;quot;, count);&lt;br /&gt;
}&lt;br /&gt;
	&lt;br /&gt;
//if there are no attached incidents, get the heck outta dodge&lt;br /&gt;
if (count == 0){&lt;br /&gt;
	return;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
i=0;&lt;br /&gt;
&lt;br /&gt;
//cycle through all incidents in the above created domset&lt;br /&gt;
for (i; i&amp;lt;count; i++) { &lt;br /&gt;
	if ( debugging_f == 1) {&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;i = %s&amp;quot;, i);&lt;br /&gt;
		}&lt;br /&gt;
	send_wait(0, attInc_domset, &amp;quot;dob_by_index&amp;quot;, &amp;quot;DEFAULT&amp;quot;, 0, 0);&lt;br /&gt;
	if (msg_error()) {&lt;br /&gt;
		errmsg=format(&amp;quot;error getting dob_by_index: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
		logf(ERROR,method+errmsg);&lt;br /&gt;
		set_return_data(errmsg);&lt;br /&gt;
		set_error(-1);&lt;br /&gt;
		return -1;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
	object this_here_inc;&lt;br /&gt;
	this_here_inc = msg[0];&lt;br /&gt;
	&lt;br /&gt;
	//need to grab this incidents persid and current status for use later&lt;br /&gt;
	string this_inc_persid, this_status_cd;&lt;br /&gt;
	this_inc_persid = this_here_inc.persistent_id;&lt;br /&gt;
	this_status_cd = this_here_inc.status;&lt;br /&gt;
	&lt;br /&gt;
	if ( debugging_f == 1) {&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;this_inc_persid = %s&amp;quot;, this_inc_persid);&lt;br /&gt;
		logf(SIGNIFICANT, &amp;quot;this_status_cd = %s&amp;quot;, this_status_cd);&lt;br /&gt;
		}&lt;br /&gt;
	&lt;br /&gt;
	//if the incident is not already closed-resolved, then update, close and log comment.&lt;br /&gt;
	if ( this_status_cd != 'CL'  ) {&lt;br /&gt;
		//check out the incident so you can update the mandatory fields&lt;br /&gt;
		object group_leader;&lt;br /&gt;
		send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error getting group_leader: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		group_leader = msg[0];&lt;br /&gt;
	&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, this_here_inc);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkout: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
	&lt;br /&gt;
		//Now set all of the necessary fields&lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;resolution_code&amp;quot;, &amp;quot;set_val&amp;quot;, rescd , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;rootcause&amp;quot;, &amp;quot;set_val&amp;quot;, this_rc , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
				&lt;br /&gt;
		//last, set status of ticket to closed-resolved&lt;br /&gt;
		send_wait(0, this_here_inc, &amp;quot;call_attr&amp;quot;, &amp;quot;status&amp;quot;, &amp;quot;set_val&amp;quot;, &amp;quot;CL&amp;quot; , &amp;quot;SURE_SET&amp;quot;);&lt;br /&gt;
			&lt;br /&gt;
		//now check back in&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkin: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}	&lt;br /&gt;
		&lt;br /&gt;
		//now, sleep and create a new activity to log the solution	&lt;br /&gt;
		sleep(3);&lt;br /&gt;
		send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error getting group_leader: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		group_leader = msg[0];	&lt;br /&gt;
	&lt;br /&gt;
		send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;alg&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader);&lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error creating new record: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
		object new_alg_obj;&lt;br /&gt;
		new_alg_obj = msg[0];&lt;br /&gt;
	&lt;br /&gt;
		//set all of the attributes of the new alg object&lt;br /&gt;
		&lt;br /&gt;
		new_alg_obj.action_desc = &amp;quot;log solution text&amp;quot;;&lt;br /&gt;
		new_alg_obj.call_req_id = this_inc_persid;&lt;br /&gt;
		new_alg_obj.description = parent_description;&lt;br /&gt;
		new_alg_obj.time_spent = 0;&lt;br /&gt;
		new_alg_obj.type = &amp;quot;SOLN&amp;quot;;&lt;br /&gt;
	&lt;br /&gt;
		//now check the new object in&lt;br /&gt;
		send_wait(0, group_leader, &amp;quot;checkin&amp;quot;); &lt;br /&gt;
		if (msg_error()) {&lt;br /&gt;
			errmsg=format(&amp;quot;error on checkin: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
			logf(ERROR,method+errmsg);&lt;br /&gt;
			set_return_data(errmsg);&lt;br /&gt;
			set_error(-1);&lt;br /&gt;
			return -1;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
	//exit loop	&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
//Now it's time to sleep and delete this object&lt;br /&gt;
sleep(3);&lt;br /&gt;
 &lt;br /&gt;
int this_id;&lt;br /&gt;
string delete_clause;&lt;br /&gt;
&lt;br /&gt;
this_id = this_crClAttIn.id;&lt;br /&gt;
delete_clause = format(&amp;quot;id=%d&amp;quot;, this_id);&lt;br /&gt;
&lt;br /&gt;
if ( debugging_f == 1) {&lt;br /&gt;
	logf(SIGNIFICANT, &amp;quot;this_id = %d&amp;quot;, this_id);&lt;br /&gt;
	logf(SIGNIFICANT, &amp;quot;delete_clause = %s&amp;quot;, delete_clause);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;api&amp;quot;, &amp;quot;delete_wc&amp;quot;, &amp;quot;z_cr_close_att_inc&amp;quot;, delete_clause, NULL); &lt;br /&gt;
if (msg_error()) {&lt;br /&gt;
		errmsg=format(&amp;quot;error on delete: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
		logf(ERROR,method+errmsg);&lt;br /&gt;
		set_return_data(errmsg);&lt;br /&gt;
		set_error(-1);&lt;br /&gt;
		return -1;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// End of z_cr_close_att_inc::z_close_att_inc()&lt;br /&gt;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;/div&gt;</summary>
		<author><name>Mbraemer</name></author>	</entry>

	<entry>
		<id>http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4309</id>
		<title>Close attached incidents</title>
		<link rel="alternate" type="text/html" href="http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4309"/>
				<updated>2011-02-22T14:07:08Z</updated>
		
		<summary type="html">&lt;p&gt;Mbraemer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I was asked by the business folk in my company to come up with a way to close all attached incidents (just like the &amp;quot;Actions, Close All Children&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
'''STEP I:''' I started by creating the following object in WSP:&lt;br /&gt;
&lt;br /&gt;
////////////////////////////////////////////////////////////////////////&lt;br /&gt;
// Factory:   z_cr_close_att_inc&lt;br /&gt;
////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
OBJECT z_cr_close_att_inc {&lt;br /&gt;
  ATTRIBUTES z_cr_close_att_inc {&lt;br /&gt;
    description STRING 4000&lt;br /&gt;
      REQUIRED;&lt;br /&gt;
    owning_pr SREL pr&lt;br /&gt;
      REQUIRED;&lt;br /&gt;
    res_code SREL resocode;&lt;br /&gt;
    root_cause SREL rc;&lt;br /&gt;
    last_mod_dt DATE { ON_CI SET NOW; };&lt;br /&gt;
    last_mod_by SREL cnt { ON_CI SET USER;&lt;br /&gt;
                           ON_NEW DEFAULT USER; };&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  FACTORY z_cr_close_att_inc {&lt;br /&gt;
    STANDARD_LISTS {&lt;br /&gt;
      MLIST OFF;&lt;br /&gt;
      RLIST OFF;&lt;br /&gt;
    };&lt;br /&gt;
    REL_ATTR id;&lt;br /&gt;
    COMMON_NAME description;&lt;br /&gt;
  };&lt;br /&gt;
  TRIGGERS {&lt;br /&gt;
    POST_CI z_close_att_inc( persistent_id ) 1040 FILTER (EVENT(&amp;quot;INSERT&amp;quot;) );&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
End of object code&lt;br /&gt;
//////////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
The only two required field here are the &amp;quot;owning_pr&amp;quot; (problem ticket srel) and the &amp;quot;description&amp;quot; (this becomes the solution. &lt;br /&gt;
The other fields are just fields in the incidents that we will update at the same time we close them. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''STEP II:''' Next, I created a detail form for the above object in WSP. I used the standard detail template but made the following changes:&lt;br /&gt;
1. Search for &amp;lt;PDM_MACRO NAME=dtlForm factory=&amp;quot;z_cr_close_att_inc&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbraemer</name></author>	</entry>

	<entry>
		<id>http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4308</id>
		<title>Close attached incidents</title>
		<link rel="alternate" type="text/html" href="http://greggsmith.net/wiki/index.php?title=Close_attached_incidents&amp;diff=4308"/>
				<updated>2011-02-22T13:52:04Z</updated>
		
		<summary type="html">&lt;p&gt;Mbraemer: Create a link in the menubar that will close all attached incidents just like the &amp;quot;Actions, Close All Children&amp;quot; closes all the children of the ticket.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I was asked by the business folk in my company to come up with a way to close all attached incidents (just like the &amp;quot;Actions, Close All Children&amp;quot;).&lt;/div&gt;</summary>
		<author><name>Mbraemer</name></author>	</entry>

	<entry>
		<id>http://greggsmith.net/wiki/index.php?title=Send_Survey_based_on_Variables&amp;diff=3543</id>
		<title>Send Survey based on Variables</title>
		<link rel="alternate" type="text/html" href="http://greggsmith.net/wiki/index.php?title=Send_Survey_based_on_Variables&amp;diff=3543"/>
				<updated>2008-11-18T16:47:34Z</updated>
		
		<summary type="html">&lt;p&gt;Mbraemer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;--[[User:Mbraemer|Mbraemer]] 09:40, 18 November 2008 (MST)&lt;br /&gt;
&lt;br /&gt;
1. First you need to create a request mulitiple notification macro that will be attached to the request. In the &amp;quot;objects&amp;quot; tab, choose affected end user.&lt;br /&gt;
This is the message template from mine. &amp;lt;server_name&amp;gt; should be changed to your url and &amp;lt;survey_template_id&amp;gt; should be changed to the id number of the survey you wish to send out. This will form the link that the user clicks:&lt;br /&gt;
&lt;br /&gt;
@{customer.combo_name} &lt;br /&gt;
You recently contacted the helpdesk about the following issue:&lt;br /&gt;
@{summary}&lt;br /&gt;
Please click on the link below and let us know about your experience&lt;br /&gt;
http://&amp;lt;server_name&amp;gt;/caisd/pdmweb.exe?OP=DO_SURVEY+SID=0+SVY_ID=&amp;lt;survey_template_id&amp;gt;+CNT_ID=@{customer}+CNTXT_PERSID=@{persistent_id}&lt;br /&gt;
&lt;br /&gt;
2. Then add this to an event with no delay or repeat values. in the &amp;quot;Action information&amp;quot; tab, select the multi notification macro in the &amp;quot;actions on true&amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
3. I had to add a field to the survey template table called &amp;quot;zcount&amp;quot; and a field to the contact record called &amp;quot;zlast_survey&amp;quot;&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
MODIFY cr POST_VALIDATE z_survey() 115 FILTER ( status { -&amp;gt; 'CL' });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
[codebox]&lt;br /&gt;
cr::z_survey(...) { &lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;Trigger Worked&amp;quot;);&lt;br /&gt;
string zcust_org;&lt;br /&gt;
int zreq_id;&lt;br /&gt;
uuid zcust_id;&lt;br /&gt;
string zreq_persid;&lt;br /&gt;
string zcust_combo;&lt;br /&gt;
string ztype;&lt;br /&gt;
string method;&lt;br /&gt;
object group_leader;&lt;br /&gt;
int do_survey;&lt;br /&gt;
string errmsg;&lt;br /&gt;
int zsurvey_tpl_id;&lt;br /&gt;
&lt;br /&gt;
zcust_org = customer.organization;&lt;br /&gt;
zreq_id = id;&lt;br /&gt;
zcust_id = customer;&lt;br /&gt;
zreq_persid = persistent_id;&lt;br /&gt;
zcust_combo = customer.combo_name;&lt;br /&gt;
ztype = type;&lt;br /&gt;
method = &amp;quot;cr::z_beazer_survey() &amp;quot;;&lt;br /&gt;
do_survey = 0;&lt;br /&gt;
&lt;br /&gt;
//These are just here to log the values to make sure it works. can be removed later&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcust_org=%s&amp;quot;,zcust_org);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zreq_id=%d&amp;quot;,zreq_id);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcust_id=%s&amp;quot;,zcust_id);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zreq_persid=%s&amp;quot;,zreq_persid);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcust_combo=%s&amp;quot;,zcust_combo);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;ztype=%s&amp;quot;,ztype);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//checks to see if customer is in a particular org and the ticket is an incident&lt;br /&gt;
if ( zcust_org == '75D6AB63316EF149B1C3FA5A1390DA40' &amp;amp;&amp;amp; ztype == &amp;quot;I&amp;quot;)&lt;br /&gt;
{&lt;br /&gt;
//this is the survey template id for this org&lt;br /&gt;
zsurvey_tpl_id = 9176281;&lt;br /&gt;
do_survey = 1;&lt;br /&gt;
}&lt;br /&gt;
//checks to see if customer is a in a different org&lt;br /&gt;
if ( zcust_org == 'D08CD8D4DA7C5C48BABB224B5089A93A')&lt;br /&gt;
{&lt;br /&gt;
//this is the template id for this org&lt;br /&gt;
zsurvey_tpl_id = 9176283;&lt;br /&gt;
do_survey = 1;&lt;br /&gt;
}&lt;br /&gt;
//if the org isn't named above,exit code&lt;br /&gt;
if (do_survey == 0)&lt;br /&gt;
{&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
//otherwise, get the survey template object.  &lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;svy_tpl&amp;quot;, &amp;quot;dob_by_id&amp;quot;, 0, zsurvey_tpl_id, NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error in svy_tpl dob_by_id: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
&lt;br /&gt;
object zsurvey_tmpl;&lt;br /&gt;
zsurvey_tmpl=msg[0];&lt;br /&gt;
&lt;br /&gt;
int zoldcount;&lt;br /&gt;
int znewcount;&lt;br /&gt;
int reset_count;&lt;br /&gt;
int ztrk_flag;&lt;br /&gt;
int zcycle;&lt;br /&gt;
string zsurv_sym;&lt;br /&gt;
&lt;br /&gt;
zoldcount = zsurvey_tmpl.zcount;&lt;br /&gt;
ztrk_flag = zsurvey_tmpl.tracking_flag;&lt;br /&gt;
zcycle = zsurvey_tmpl.submit_cycle;&lt;br /&gt;
zsurv_sym = zsurvey_tmpl.sym;&lt;br /&gt;
znewcount = zoldcount +1;&lt;br /&gt;
reset_count = 0;&lt;br /&gt;
&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zoldcount=%d&amp;quot;,zoldcount);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;ztrk_flag=%d&amp;quot;,ztrk_flag);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcycle=%d&amp;quot;,zcycle);&lt;br /&gt;
&lt;br /&gt;
//if stricker rules is selected, this will pull the customer dob and check the last survey field&lt;br /&gt;
if (ztrk_flag == 1){&lt;br /&gt;
//get the customer object&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;cnt&amp;quot;, &amp;quot;dob_by_id&amp;quot;, 0, zcust_id, NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error in cnt dob_by_id: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
object zcustomer_obj;&lt;br /&gt;
zcustomer_obj =msg[0];&lt;br /&gt;
&lt;br /&gt;
date zlast_surv;&lt;br /&gt;
date znow_time;&lt;br /&gt;
duration ztimer;&lt;br /&gt;
&lt;br /&gt;
if (is_null(zcustomer_obj.zlast_survey))&lt;br /&gt;
{zlast_surv = 0;}&lt;br /&gt;
else&lt;br /&gt;
{zlast_surv = zcustomer_obj.zlast_survey;}&lt;br /&gt;
znow_time = now();&lt;br /&gt;
ztimer = znow_time-zlast_surv;&lt;br /&gt;
&lt;br /&gt;
//if last survey was less than 90days ago, exit code&lt;br /&gt;
if (ztimer &amp;lt; 7776000) {&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
//now we need to check the cycle field.&lt;br /&gt;
//get group leader so we can check out the svy tpl object and make changes&lt;br /&gt;
      send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
      if (msg_error()) {&lt;br /&gt;
            errmsg = format(&amp;quot;%s get_co_group error '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
            logf(ERROR, errmsg);&lt;br /&gt;
            set_return_data(errmsg);&lt;br /&gt;
            set_error(1);&lt;br /&gt;
            return -1;&lt;br /&gt;
            }&lt;br /&gt;
group_leader = msg[0];&lt;br /&gt;
&lt;br /&gt;
// check out the sry_tpl obj since we are updating it.&lt;br /&gt;
            send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, zsurvey_tmpl);&lt;br /&gt;
            if (msg_error()) {&lt;br /&gt;
                        errmsg = format(&amp;quot;checkout svy_tpl obj '%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                        logf(ERROR, errmsg);&lt;br /&gt;
                        set_return_data(errmsg);&lt;br /&gt;
                        set_error(1);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                        } &lt;br /&gt;
&lt;br /&gt;
//if the submit cycle number hasn't been reached. add one, check in  and exit code.&lt;br /&gt;
if (znewcount &amp;lt; zcycle){&lt;br /&gt;
send_wait(0, zsurvey_tmpl, &amp;quot;call_attr&amp;quot;, &amp;quot;zcount&amp;quot;, &amp;quot;set_val&amp;quot;, znewcount , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error setting zlast_survey: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
//check the svy_tpl obj in&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
                if (msg_error()) {&lt;br /&gt;
                    errmsg = format(&amp;quot;checkin svy_tpl obj'%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                    logf(ERROR, errmsg);&lt;br /&gt;
                    send_wait(0, group_leader, &amp;quot;uncheck&amp;quot;);&lt;br /&gt;
                    set_return_data(errmsg);&lt;br /&gt;
                      set_error(1);&lt;br /&gt;
                    return -1;&lt;br /&gt;
                    };&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
//else,set the count back to zero and continue through the code&lt;br /&gt;
else {&lt;br /&gt;
send_wait(0, zsurvey_tmpl, &amp;quot;call_attr&amp;quot;, &amp;quot;zcount&amp;quot;, &amp;quot;set_val&amp;quot;, reset_count , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error setting zlast_survey: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
//check the svy_tpl obj in&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
                if (msg_error()) {&lt;br /&gt;
                    errmsg = format(&amp;quot;checkin svy_tpl obj'%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                    logf(ERROR, errmsg);&lt;br /&gt;
                    send_wait(0, group_leader, &amp;quot;uncheck&amp;quot;);&lt;br /&gt;
                    set_return_data(errmsg);&lt;br /&gt;
                      set_error(1);&lt;br /&gt;
                    return -1;&lt;br /&gt;
                    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//this bit of code only fires if stricker rules if enforced&lt;br /&gt;
//we get the customer obj, reset the last survey field to now.&lt;br /&gt;
if (ztrk_flag == 1) {&lt;br /&gt;
// get a group leader so can make changes to the customer obj&lt;br /&gt;
      send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
      if (msg_error()) {&lt;br /&gt;
            errmsg = format(&amp;quot;%s get_co_group error '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
            logf(ERROR, errmsg);&lt;br /&gt;
            set_return_data(errmsg);&lt;br /&gt;
            set_error(1);&lt;br /&gt;
            return -1;&lt;br /&gt;
            }&lt;br /&gt;
group_leader = msg[0];&lt;br /&gt;
&lt;br /&gt;
// check out the customer obj since we are updating it.&lt;br /&gt;
            send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, zcustomer_obj);&lt;br /&gt;
            if (msg_error()) {&lt;br /&gt;
                        errmsg = format(&amp;quot;checkout customer obj '%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                        logf(ERROR, errmsg);&lt;br /&gt;
                        set_return_data(errmsg);&lt;br /&gt;
                        set_error(1);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                        } &lt;br /&gt;
//set the zlast_survey field to now&lt;br /&gt;
send_wait(0, zcustomer_obj, &amp;quot;call_attr&amp;quot;, &amp;quot;zlast_survey&amp;quot;, &amp;quot;set_val&amp;quot;, znow_time , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error setting zlast_survey: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
//check the customer obj in&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
                if (msg_error()) {&lt;br /&gt;
                    errmsg = format(&amp;quot;checkin customer obj'%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                    logf(ERROR, errmsg);&lt;br /&gt;
                    send_wait(0, group_leader, &amp;quot;uncheck&amp;quot;);&lt;br /&gt;
                    set_return_data(errmsg);&lt;br /&gt;
                      set_error(1);&lt;br /&gt;
                    return -1;&lt;br /&gt;
                    }&lt;br /&gt;
 &lt;br /&gt;
//Now, create a surrvey tracking record. This prevents survey from being filled out more than once&lt;br /&gt;
object survey_track_record;&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error getting group leader: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
group_leader = msg[0]; &lt;br /&gt;
&lt;br /&gt;
send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;svytrk&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error creating new svytrk ob: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
survey_track_record = msg[0]; &lt;br /&gt;
&lt;br /&gt;
survey_track_record.tplid = zsurvey_tpl_id;&lt;br /&gt;
survey_track_record.cntid = zcust_id;&lt;br /&gt;
survey_track_record.object_type = &amp;quot;cr&amp;quot;;&lt;br /&gt;
survey_track_record.object_id = zreq_id;&lt;br /&gt;
survey_track_record.notif_dt = znow_time;&lt;br /&gt;
&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//regardless if stricker rules is selected or not, we need to add a survey sent activity record&lt;br /&gt;
&lt;br /&gt;
object activity_log_record;&lt;br /&gt;
string zalg_descr;&lt;br /&gt;
&lt;br /&gt;
//this will format the description like the ones I saw in the activity log&lt;br /&gt;
zalg_descr = format(&amp;quot;Survey Request ('%s') sent to %s&amp;quot;, zsurv_sym,zcust_combo);&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error getting group leader: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
group_leader = msg[0]; &lt;br /&gt;
&lt;br /&gt;
send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;alg&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error creating new alg ob: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
activity_log_record = msg[0]; &lt;br /&gt;
&lt;br /&gt;
activity_log_record.call_req_id = zreq_persid;&lt;br /&gt;
//this is the system ahd contact record id.&lt;br /&gt;
activity_log_record.analyst = &amp;quot;793ED69B4E87A545BD8E911834D829FC&amp;quot;;&lt;br /&gt;
activity_log_record.description = zalg_descr;&lt;br /&gt;
activity_log_record.action_desc = zalg_descr;&lt;br /&gt;
activity_log_record.type = &amp;quot;SRVY_SENT&amp;quot;;&lt;br /&gt;
activity_log_record.internal = 0;&lt;br /&gt;
&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
//finally, attach the event that sends out the message with the link&lt;br /&gt;
object attached_events_table_record;&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;zalglog () - Attach Event: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
group_leader = msg[0]; &lt;br /&gt;
&lt;br /&gt;
send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;atev&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;error attaching event '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
}&lt;br /&gt;
attached_events_table_record = msg[0]; &lt;br /&gt;
attached_events_table_record.obj_id = zreq_persid;&lt;br /&gt;
if (zsurvey_tpl_id == 9176281)&lt;br /&gt;
//first org's survey from way up above&lt;br /&gt;
{&lt;br /&gt;
//evt:9452506 should be replaced with the event you created. I have two different &lt;br /&gt;
//surveys. If you only have one, remove the extra coding. &lt;br /&gt;
attached_events_table_record.event_tmpl = &amp;quot;evt:9452506&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
if (zsurvey_tpl_id == 9176283)&lt;br /&gt;
//second org's survey&lt;br /&gt;
{&lt;br /&gt;
attached_events_table_record.event_tmpl = &amp;quot;evt:10224927&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
[/codebox]&lt;/div&gt;</summary>
		<author><name>Mbraemer</name></author>	</entry>

	<entry>
		<id>http://greggsmith.net/wiki/index.php?title=Send_Survey_based_on_Variables&amp;diff=3542</id>
		<title>Send Survey based on Variables</title>
		<link rel="alternate" type="text/html" href="http://greggsmith.net/wiki/index.php?title=Send_Survey_based_on_Variables&amp;diff=3542"/>
				<updated>2008-11-18T16:45:34Z</updated>
		
		<summary type="html">&lt;p&gt;Mbraemer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;--[[User:Mbraemer|Mbraemer]] 09:40, 18 November 2008 (MST)&lt;br /&gt;
&lt;br /&gt;
1. First you need to create a request mulitiple notification macro that will be attached to the request. In the &amp;quot;objects&amp;quot; tab, choose affected end user.&lt;br /&gt;
This is the message template from mine. &amp;lt;server_name&amp;gt; should be changed to your url and &amp;lt;survey_template_id&amp;gt; should be changed to the id number of the survey you wish to send out. This will form the link that the user clicks:&lt;br /&gt;
&lt;br /&gt;
@{customer.combo_name} &lt;br /&gt;
You recently contacted the helpdesk about the following issue:&lt;br /&gt;
@{summary}&lt;br /&gt;
Please click on the link below and let us know about your experience&lt;br /&gt;
http://&amp;lt;server_name&amp;gt;/caisd/pdmweb.exe?OP=DO_SURVEY+SID=0+SVY_ID=&amp;lt;survey_template_id&amp;gt;+CNT_ID=@{customer}+CNTXT_PERSID=@{persistent_id}&lt;br /&gt;
&lt;br /&gt;
2. Then add this to an event with no delay or repeat values. in the &amp;quot;Action information&amp;quot; tab, select the multi notification macro in the &amp;quot;actions on true&amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
3. I had to add a field to the survey template table called &amp;quot;zcount&amp;quot; and a field to the contact record called &amp;quot;zlast_survey&amp;quot;&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
MODIFY cr POST_VALIDATE z_survey() 115 FILTER ( status { -&amp;gt; 'CL' });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
cr::z_survey(...) { &lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;Trigger Worked&amp;quot;);&lt;br /&gt;
string zcust_org;&lt;br /&gt;
int zreq_id;&lt;br /&gt;
uuid zcust_id;&lt;br /&gt;
string zreq_persid;&lt;br /&gt;
string zcust_combo;&lt;br /&gt;
string ztype;&lt;br /&gt;
string method;&lt;br /&gt;
object group_leader;&lt;br /&gt;
int do_survey;&lt;br /&gt;
string errmsg;&lt;br /&gt;
int zsurvey_tpl_id;&lt;br /&gt;
&lt;br /&gt;
zcust_org = customer.organization;&lt;br /&gt;
zreq_id = id;&lt;br /&gt;
zcust_id = customer;&lt;br /&gt;
zreq_persid = persistent_id;&lt;br /&gt;
zcust_combo = customer.combo_name;&lt;br /&gt;
ztype = type;&lt;br /&gt;
method = &amp;quot;cr::z_beazer_survey() &amp;quot;;&lt;br /&gt;
do_survey = 0;&lt;br /&gt;
&lt;br /&gt;
//These are just here to log the values to make sure it works. can be removed later&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcust_org=%s&amp;quot;,zcust_org);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zreq_id=%d&amp;quot;,zreq_id);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcust_id=%s&amp;quot;,zcust_id);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zreq_persid=%s&amp;quot;,zreq_persid);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcust_combo=%s&amp;quot;,zcust_combo);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;ztype=%s&amp;quot;,ztype);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//checks to see if customer is in a particular org and the ticket is an incident&lt;br /&gt;
if ( zcust_org == '75D6AB63316EF149B1C3FA5A1390DA40' &amp;amp;&amp;amp; ztype == &amp;quot;I&amp;quot;)&lt;br /&gt;
{&lt;br /&gt;
//this is the survey template id for this org&lt;br /&gt;
zsurvey_tpl_id = 9176281;&lt;br /&gt;
do_survey = 1;&lt;br /&gt;
}&lt;br /&gt;
//checks to see if customer is a in a different org&lt;br /&gt;
if ( zcust_org == 'D08CD8D4DA7C5C48BABB224B5089A93A')&lt;br /&gt;
{&lt;br /&gt;
//this is the template id for this org&lt;br /&gt;
zsurvey_tpl_id = 9176283;&lt;br /&gt;
do_survey = 1;&lt;br /&gt;
}&lt;br /&gt;
//if the org isn't named above,exit code&lt;br /&gt;
if (do_survey == 0)&lt;br /&gt;
{&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
//otherwise, get the survey template object.  &lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;svy_tpl&amp;quot;, &amp;quot;dob_by_id&amp;quot;, 0, zsurvey_tpl_id, NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error in svy_tpl dob_by_id: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
&lt;br /&gt;
object zsurvey_tmpl;&lt;br /&gt;
zsurvey_tmpl=msg[0];&lt;br /&gt;
&lt;br /&gt;
int zoldcount;&lt;br /&gt;
int znewcount;&lt;br /&gt;
int reset_count;&lt;br /&gt;
int ztrk_flag;&lt;br /&gt;
int zcycle;&lt;br /&gt;
string zsurv_sym;&lt;br /&gt;
&lt;br /&gt;
zoldcount = zsurvey_tmpl.zcount;&lt;br /&gt;
ztrk_flag = zsurvey_tmpl.tracking_flag;&lt;br /&gt;
zcycle = zsurvey_tmpl.submit_cycle;&lt;br /&gt;
zsurv_sym = zsurvey_tmpl.sym;&lt;br /&gt;
znewcount = zoldcount +1;&lt;br /&gt;
reset_count = 0;&lt;br /&gt;
&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zoldcount=%d&amp;quot;,zoldcount);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;ztrk_flag=%d&amp;quot;,ztrk_flag);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcycle=%d&amp;quot;,zcycle);&lt;br /&gt;
&lt;br /&gt;
//if stricker rules is selected, this will pull the customer dob and check the last survey field&lt;br /&gt;
if (ztrk_flag == 1){&lt;br /&gt;
//get the customer object&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;cnt&amp;quot;, &amp;quot;dob_by_id&amp;quot;, 0, zcust_id, NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error in cnt dob_by_id: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
object zcustomer_obj;&lt;br /&gt;
zcustomer_obj =msg[0];&lt;br /&gt;
&lt;br /&gt;
date zlast_surv;&lt;br /&gt;
date znow_time;&lt;br /&gt;
duration ztimer;&lt;br /&gt;
&lt;br /&gt;
if (is_null(zcustomer_obj.zlast_survey))&lt;br /&gt;
{zlast_surv = 0;}&lt;br /&gt;
else&lt;br /&gt;
{zlast_surv = zcustomer_obj.zlast_survey;}&lt;br /&gt;
znow_time = now();&lt;br /&gt;
ztimer = znow_time-zlast_surv;&lt;br /&gt;
&lt;br /&gt;
//if last survey was less than 90days ago, exit code&lt;br /&gt;
if (ztimer &amp;lt; 7776000) {&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
//now we need to check the cycle field.&lt;br /&gt;
//get group leader so we can check out the svy tpl object and make changes&lt;br /&gt;
      send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
      if (msg_error()) {&lt;br /&gt;
            errmsg = format(&amp;quot;%s get_co_group error '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
            logf(ERROR, errmsg);&lt;br /&gt;
            set_return_data(errmsg);&lt;br /&gt;
            set_error(1);&lt;br /&gt;
            return -1;&lt;br /&gt;
            }&lt;br /&gt;
group_leader = msg[0];&lt;br /&gt;
&lt;br /&gt;
// check out the sry_tpl obj since we are updating it.&lt;br /&gt;
            send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, zsurvey_tmpl);&lt;br /&gt;
            if (msg_error()) {&lt;br /&gt;
                        errmsg = format(&amp;quot;checkout svy_tpl obj '%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                        logf(ERROR, errmsg);&lt;br /&gt;
                        set_return_data(errmsg);&lt;br /&gt;
                        set_error(1);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                        } &lt;br /&gt;
&lt;br /&gt;
//if the submit cycle number hasn't been reached. add one, check in  and exit code.&lt;br /&gt;
if (znewcount &amp;lt; zcycle){&lt;br /&gt;
send_wait(0, zsurvey_tmpl, &amp;quot;call_attr&amp;quot;, &amp;quot;zcount&amp;quot;, &amp;quot;set_val&amp;quot;, znewcount , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error setting zlast_survey: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
//check the svy_tpl obj in&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
                if (msg_error()) {&lt;br /&gt;
                    errmsg = format(&amp;quot;checkin svy_tpl obj'%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                    logf(ERROR, errmsg);&lt;br /&gt;
                    send_wait(0, group_leader, &amp;quot;uncheck&amp;quot;);&lt;br /&gt;
                    set_return_data(errmsg);&lt;br /&gt;
                      set_error(1);&lt;br /&gt;
                    return -1;&lt;br /&gt;
                    };&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
//else,set the count back to zero and continue through the code&lt;br /&gt;
else {&lt;br /&gt;
send_wait(0, zsurvey_tmpl, &amp;quot;call_attr&amp;quot;, &amp;quot;zcount&amp;quot;, &amp;quot;set_val&amp;quot;, reset_count , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error setting zlast_survey: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
//check the svy_tpl obj in&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
                if (msg_error()) {&lt;br /&gt;
                    errmsg = format(&amp;quot;checkin svy_tpl obj'%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                    logf(ERROR, errmsg);&lt;br /&gt;
                    send_wait(0, group_leader, &amp;quot;uncheck&amp;quot;);&lt;br /&gt;
                    set_return_data(errmsg);&lt;br /&gt;
                      set_error(1);&lt;br /&gt;
                    return -1;&lt;br /&gt;
                    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//this bit of code only fires if stricker rules if enforced&lt;br /&gt;
//we get the customer obj, reset the last survey field to now.&lt;br /&gt;
if (ztrk_flag == 1) {&lt;br /&gt;
// get a group leader so can make changes to the customer obj&lt;br /&gt;
      send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
      if (msg_error()) {&lt;br /&gt;
            errmsg = format(&amp;quot;%s get_co_group error '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
            logf(ERROR, errmsg);&lt;br /&gt;
            set_return_data(errmsg);&lt;br /&gt;
            set_error(1);&lt;br /&gt;
            return -1;&lt;br /&gt;
            }&lt;br /&gt;
group_leader = msg[0];&lt;br /&gt;
&lt;br /&gt;
// check out the customer obj since we are updating it.&lt;br /&gt;
            send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, zcustomer_obj);&lt;br /&gt;
            if (msg_error()) {&lt;br /&gt;
                        errmsg = format(&amp;quot;checkout customer obj '%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                        logf(ERROR, errmsg);&lt;br /&gt;
                        set_return_data(errmsg);&lt;br /&gt;
                        set_error(1);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                        } &lt;br /&gt;
//set the zlast_survey field to now&lt;br /&gt;
send_wait(0, zcustomer_obj, &amp;quot;call_attr&amp;quot;, &amp;quot;zlast_survey&amp;quot;, &amp;quot;set_val&amp;quot;, znow_time , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error setting zlast_survey: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
//check the customer obj in&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
                if (msg_error()) {&lt;br /&gt;
                    errmsg = format(&amp;quot;checkin customer obj'%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                    logf(ERROR, errmsg);&lt;br /&gt;
                    send_wait(0, group_leader, &amp;quot;uncheck&amp;quot;);&lt;br /&gt;
                    set_return_data(errmsg);&lt;br /&gt;
                      set_error(1);&lt;br /&gt;
                    return -1;&lt;br /&gt;
                    }&lt;br /&gt;
 &lt;br /&gt;
//Now, create a surrvey tracking record. This prevents survey from being filled out more than once&lt;br /&gt;
object survey_track_record;&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error getting group leader: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
group_leader = msg[0]; &lt;br /&gt;
&lt;br /&gt;
send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;svytrk&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error creating new svytrk ob: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
survey_track_record = msg[0]; &lt;br /&gt;
&lt;br /&gt;
survey_track_record.tplid = zsurvey_tpl_id;&lt;br /&gt;
survey_track_record.cntid = zcust_id;&lt;br /&gt;
survey_track_record.object_type = &amp;quot;cr&amp;quot;;&lt;br /&gt;
survey_track_record.object_id = zreq_id;&lt;br /&gt;
survey_track_record.notif_dt = znow_time;&lt;br /&gt;
&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//regardless if stricker rules is selected or not, we need to add a survey sent activity record&lt;br /&gt;
&lt;br /&gt;
object activity_log_record;&lt;br /&gt;
string zalg_descr;&lt;br /&gt;
&lt;br /&gt;
//this will format the description like the ones I saw in the activity log&lt;br /&gt;
zalg_descr = format(&amp;quot;Survey Request ('%s') sent to %s&amp;quot;, zsurv_sym,zcust_combo);&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error getting group leader: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
group_leader = msg[0]; &lt;br /&gt;
&lt;br /&gt;
send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;alg&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error creating new alg ob: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
activity_log_record = msg[0]; &lt;br /&gt;
&lt;br /&gt;
activity_log_record.call_req_id = zreq_persid;&lt;br /&gt;
//this is the system ahd contact record id.&lt;br /&gt;
activity_log_record.analyst = &amp;quot;793ED69B4E87A545BD8E911834D829FC&amp;quot;;&lt;br /&gt;
activity_log_record.description = zalg_descr;&lt;br /&gt;
activity_log_record.action_desc = zalg_descr;&lt;br /&gt;
activity_log_record.type = &amp;quot;SRVY_SENT&amp;quot;;&lt;br /&gt;
activity_log_record.internal = 0;&lt;br /&gt;
&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
//finally, attach the event that sends out the message with the link&lt;br /&gt;
object attached_events_table_record;&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;zalglog () - Attach Event: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
group_leader = msg[0]; &lt;br /&gt;
&lt;br /&gt;
send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;atev&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;error attaching event '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
}&lt;br /&gt;
attached_events_table_record = msg[0]; &lt;br /&gt;
attached_events_table_record.obj_id = zreq_persid;&lt;br /&gt;
if (zsurvey_tpl_id == 9176281)&lt;br /&gt;
//first org's survey from way up above&lt;br /&gt;
{&lt;br /&gt;
//evt:9452506 should be replaced with the event you created. I have two different &lt;br /&gt;
//surveys. If you only have one, remove the extra coding. &lt;br /&gt;
attached_events_table_record.event_tmpl = &amp;quot;evt:9452506&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
if (zsurvey_tpl_id == 9176283)&lt;br /&gt;
//second org's survey&lt;br /&gt;
{&lt;br /&gt;
attached_events_table_record.event_tmpl = &amp;quot;evt:10224927&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>Mbraemer</name></author>	</entry>

	<entry>
		<id>http://greggsmith.net/wiki/index.php?title=Send_Survey_based_on_Variables&amp;diff=3541</id>
		<title>Send Survey based on Variables</title>
		<link rel="alternate" type="text/html" href="http://greggsmith.net/wiki/index.php?title=Send_Survey_based_on_Variables&amp;diff=3541"/>
				<updated>2008-11-18T16:41:57Z</updated>
		
		<summary type="html">&lt;p&gt;Mbraemer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;--[[User:Mbraemer|Mbraemer]] 09:40, 18 November 2008 (MST)&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
1. First you need to create a request mulitiple notification macro that will be attached to the request. In the &amp;quot;objects&amp;quot; tab, choose affected end user.&lt;br /&gt;
This is the message template from mine. &amp;lt;server_name&amp;gt; should be changed to your url and &amp;lt;survey_template_id&amp;gt; should be changed to the id number of the survey you wish to send out. This will form the link that the user clicks:&lt;br /&gt;
&lt;br /&gt;
@{customer.combo_name} &lt;br /&gt;
You recently contacted the helpdesk about the following issue:&lt;br /&gt;
@{summary}&lt;br /&gt;
Please click on the link below and let us know about your experience&lt;br /&gt;
http://&amp;lt;server_name&amp;gt;/caisd/pdmweb.exe?OP=DO_SURVEY+SID=0+SVY_ID=&amp;lt;survey_template_id&amp;gt;+CNT_ID=@{customer}+CNTXT_PERSID=@{persistent_id}&lt;br /&gt;
&lt;br /&gt;
2. Then add this to an event with no delay or repeat values. in the &amp;quot;Action information&amp;quot; tab, select the multi notification macro in the &amp;quot;actions on true&amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
3. I had to add a field to the survey template table called &amp;quot;zcount&amp;quot; and a field to the contact record called &amp;quot;zlast_survey&amp;quot;&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
MODIFY cr POST_VALIDATE z_survey() 115 FILTER ( status { -&amp;gt; 'CL' });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
cr::z_survey(...) { &lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;Trigger Worked&amp;quot;);&lt;br /&gt;
string zcust_org;&lt;br /&gt;
int zreq_id;&lt;br /&gt;
uuid zcust_id;&lt;br /&gt;
string zreq_persid;&lt;br /&gt;
string zcust_combo;&lt;br /&gt;
string ztype;&lt;br /&gt;
string method;&lt;br /&gt;
object group_leader;&lt;br /&gt;
int do_survey;&lt;br /&gt;
string errmsg;&lt;br /&gt;
int zsurvey_tpl_id;&lt;br /&gt;
&lt;br /&gt;
zcust_org = customer.organization;&lt;br /&gt;
zreq_id = id;&lt;br /&gt;
zcust_id = customer;&lt;br /&gt;
zreq_persid = persistent_id;&lt;br /&gt;
zcust_combo = customer.combo_name;&lt;br /&gt;
ztype = type;&lt;br /&gt;
method = &amp;quot;cr::z_beazer_survey() &amp;quot;;&lt;br /&gt;
do_survey = 0;&lt;br /&gt;
&lt;br /&gt;
//These are just here to log the values to make sure it works. can be removed later&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcust_org=%s&amp;quot;,zcust_org);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zreq_id=%d&amp;quot;,zreq_id);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcust_id=%s&amp;quot;,zcust_id);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zreq_persid=%s&amp;quot;,zreq_persid);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcust_combo=%s&amp;quot;,zcust_combo);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;ztype=%s&amp;quot;,ztype);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//checks to see if customer is in a particular org and the ticket is an incident&lt;br /&gt;
if ( zcust_org == '75D6AB63316EF149B1C3FA5A1390DA40' &amp;amp;&amp;amp; ztype == &amp;quot;I&amp;quot;)&lt;br /&gt;
{&lt;br /&gt;
//this is the survey template id for this org&lt;br /&gt;
zsurvey_tpl_id = 9176281;&lt;br /&gt;
do_survey = 1;&lt;br /&gt;
}&lt;br /&gt;
//checks to see if customer is a in a different org&lt;br /&gt;
if ( zcust_org == 'D08CD8D4DA7C5C48BABB224B5089A93A')&lt;br /&gt;
{&lt;br /&gt;
//this is the template id for this org&lt;br /&gt;
zsurvey_tpl_id = 9176283;&lt;br /&gt;
do_survey = 1;&lt;br /&gt;
}&lt;br /&gt;
//if the org isn't named above,exit code&lt;br /&gt;
if (do_survey == 0)&lt;br /&gt;
{&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
//otherwise, get the survey template object.  &lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;svy_tpl&amp;quot;, &amp;quot;dob_by_id&amp;quot;, 0, zsurvey_tpl_id, NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error in svy_tpl dob_by_id: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
&lt;br /&gt;
object zsurvey_tmpl;&lt;br /&gt;
zsurvey_tmpl=msg[0];&lt;br /&gt;
&lt;br /&gt;
int zoldcount;&lt;br /&gt;
int znewcount;&lt;br /&gt;
int reset_count;&lt;br /&gt;
int ztrk_flag;&lt;br /&gt;
int zcycle;&lt;br /&gt;
string zsurv_sym;&lt;br /&gt;
&lt;br /&gt;
zoldcount = zsurvey_tmpl.zcount;&lt;br /&gt;
ztrk_flag = zsurvey_tmpl.tracking_flag;&lt;br /&gt;
zcycle = zsurvey_tmpl.submit_cycle;&lt;br /&gt;
zsurv_sym = zsurvey_tmpl.sym;&lt;br /&gt;
znewcount = zoldcount +1;&lt;br /&gt;
reset_count = 0;&lt;br /&gt;
&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zoldcount=%d&amp;quot;,zoldcount);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;ztrk_flag=%d&amp;quot;,ztrk_flag);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcycle=%d&amp;quot;,zcycle);&lt;br /&gt;
&lt;br /&gt;
//if stricker rules is selected, this will pull the customer dob and check the last survey field&lt;br /&gt;
if (ztrk_flag == 1){&lt;br /&gt;
//get the customer object&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;cnt&amp;quot;, &amp;quot;dob_by_id&amp;quot;, 0, zcust_id, NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error in cnt dob_by_id: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
object zcustomer_obj;&lt;br /&gt;
zcustomer_obj =msg[0];&lt;br /&gt;
&lt;br /&gt;
date zlast_surv;&lt;br /&gt;
date znow_time;&lt;br /&gt;
duration ztimer;&lt;br /&gt;
&lt;br /&gt;
if (is_null(zcustomer_obj.zlast_survey))&lt;br /&gt;
{zlast_surv = 0;}&lt;br /&gt;
else&lt;br /&gt;
{zlast_surv = zcustomer_obj.zlast_survey;}&lt;br /&gt;
znow_time = now();&lt;br /&gt;
ztimer = znow_time-zlast_surv;&lt;br /&gt;
&lt;br /&gt;
//if last survey was less than 90days ago, exit code&lt;br /&gt;
if (ztimer &amp;lt; 7776000) {&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
//now we need to check the cycle field.&lt;br /&gt;
//get group leader so we can check out the svy tpl object and make changes&lt;br /&gt;
      send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
      if (msg_error()) {&lt;br /&gt;
            errmsg = format(&amp;quot;%s get_co_group error '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
            logf(ERROR, errmsg);&lt;br /&gt;
            set_return_data(errmsg);&lt;br /&gt;
            set_error(1);&lt;br /&gt;
            return -1;&lt;br /&gt;
            }&lt;br /&gt;
group_leader = msg[0];&lt;br /&gt;
&lt;br /&gt;
// check out the sry_tpl obj since we are updating it.&lt;br /&gt;
            send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, zsurvey_tmpl);&lt;br /&gt;
            if (msg_error()) {&lt;br /&gt;
                        errmsg = format(&amp;quot;checkout svy_tpl obj '%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                        logf(ERROR, errmsg);&lt;br /&gt;
                        set_return_data(errmsg);&lt;br /&gt;
                        set_error(1);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                        } &lt;br /&gt;
&lt;br /&gt;
//if the submit cycle number hasn't been reached. add one, check in  and exit code.&lt;br /&gt;
if (znewcount &amp;lt; zcycle){&lt;br /&gt;
send_wait(0, zsurvey_tmpl, &amp;quot;call_attr&amp;quot;, &amp;quot;zcount&amp;quot;, &amp;quot;set_val&amp;quot;, znewcount , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error setting zlast_survey: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
//check the svy_tpl obj in&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
                if (msg_error()) {&lt;br /&gt;
                    errmsg = format(&amp;quot;checkin svy_tpl obj'%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                    logf(ERROR, errmsg);&lt;br /&gt;
                    send_wait(0, group_leader, &amp;quot;uncheck&amp;quot;);&lt;br /&gt;
                    set_return_data(errmsg);&lt;br /&gt;
                      set_error(1);&lt;br /&gt;
                    return -1;&lt;br /&gt;
                    };&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
//else,set the count back to zero and continue through the code&lt;br /&gt;
else {&lt;br /&gt;
send_wait(0, zsurvey_tmpl, &amp;quot;call_attr&amp;quot;, &amp;quot;zcount&amp;quot;, &amp;quot;set_val&amp;quot;, reset_count , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error setting zlast_survey: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
//check the svy_tpl obj in&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
                if (msg_error()) {&lt;br /&gt;
                    errmsg = format(&amp;quot;checkin svy_tpl obj'%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                    logf(ERROR, errmsg);&lt;br /&gt;
                    send_wait(0, group_leader, &amp;quot;uncheck&amp;quot;);&lt;br /&gt;
                    set_return_data(errmsg);&lt;br /&gt;
                      set_error(1);&lt;br /&gt;
                    return -1;&lt;br /&gt;
                    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//this bit of code only fires if stricker rules if enforced&lt;br /&gt;
//we get the customer obj, reset the last survey field to now.&lt;br /&gt;
if (ztrk_flag == 1) {&lt;br /&gt;
// get a group leader so can make changes to the customer obj&lt;br /&gt;
      send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
      if (msg_error()) {&lt;br /&gt;
            errmsg = format(&amp;quot;%s get_co_group error '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
            logf(ERROR, errmsg);&lt;br /&gt;
            set_return_data(errmsg);&lt;br /&gt;
            set_error(1);&lt;br /&gt;
            return -1;&lt;br /&gt;
            }&lt;br /&gt;
group_leader = msg[0];&lt;br /&gt;
&lt;br /&gt;
// check out the customer obj since we are updating it.&lt;br /&gt;
            send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, zcustomer_obj);&lt;br /&gt;
            if (msg_error()) {&lt;br /&gt;
                        errmsg = format(&amp;quot;checkout customer obj '%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                        logf(ERROR, errmsg);&lt;br /&gt;
                        set_return_data(errmsg);&lt;br /&gt;
                        set_error(1);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                        } &lt;br /&gt;
//set the zlast_survey field to now&lt;br /&gt;
send_wait(0, zcustomer_obj, &amp;quot;call_attr&amp;quot;, &amp;quot;zlast_survey&amp;quot;, &amp;quot;set_val&amp;quot;, znow_time , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error setting zlast_survey: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
//check the customer obj in&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
                if (msg_error()) {&lt;br /&gt;
                    errmsg = format(&amp;quot;checkin customer obj'%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                    logf(ERROR, errmsg);&lt;br /&gt;
                    send_wait(0, group_leader, &amp;quot;uncheck&amp;quot;);&lt;br /&gt;
                    set_return_data(errmsg);&lt;br /&gt;
                      set_error(1);&lt;br /&gt;
                    return -1;&lt;br /&gt;
                    }&lt;br /&gt;
 &lt;br /&gt;
//Now, create a surrvey tracking record. This prevents survey from being filled out more than once&lt;br /&gt;
object survey_track_record;&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error getting group leader: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
group_leader = msg[0]; &lt;br /&gt;
&lt;br /&gt;
send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;svytrk&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error creating new svytrk ob: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
survey_track_record = msg[0]; &lt;br /&gt;
&lt;br /&gt;
survey_track_record.tplid = zsurvey_tpl_id;&lt;br /&gt;
survey_track_record.cntid = zcust_id;&lt;br /&gt;
survey_track_record.object_type = &amp;quot;cr&amp;quot;;&lt;br /&gt;
survey_track_record.object_id = zreq_id;&lt;br /&gt;
survey_track_record.notif_dt = znow_time;&lt;br /&gt;
&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//regardless if stricker rules is selected or not, we need to add a survey sent activity record&lt;br /&gt;
&lt;br /&gt;
object activity_log_record;&lt;br /&gt;
string zalg_descr;&lt;br /&gt;
&lt;br /&gt;
//this will format the description like the ones I saw in the activity log&lt;br /&gt;
zalg_descr = format(&amp;quot;Survey Request ('%s') sent to %s&amp;quot;, zsurv_sym,zcust_combo);&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error getting group leader: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
group_leader = msg[0]; &lt;br /&gt;
&lt;br /&gt;
send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;alg&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error creating new alg ob: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
activity_log_record = msg[0]; &lt;br /&gt;
&lt;br /&gt;
activity_log_record.call_req_id = zreq_persid;&lt;br /&gt;
//this is the system ahd contact record id.&lt;br /&gt;
activity_log_record.analyst = &amp;quot;793ED69B4E87A545BD8E911834D829FC&amp;quot;;&lt;br /&gt;
activity_log_record.description = zalg_descr;&lt;br /&gt;
activity_log_record.action_desc = zalg_descr;&lt;br /&gt;
activity_log_record.type = &amp;quot;SRVY_SENT&amp;quot;;&lt;br /&gt;
activity_log_record.internal = 0;&lt;br /&gt;
&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
//finally, attach the event that sends out the message with the link&lt;br /&gt;
object attached_events_table_record;&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;zalglog () - Attach Event: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
group_leader = msg[0]; &lt;br /&gt;
&lt;br /&gt;
send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;atev&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;error attaching event '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
}&lt;br /&gt;
attached_events_table_record = msg[0]; &lt;br /&gt;
attached_events_table_record.obj_id = zreq_persid;&lt;br /&gt;
if (zsurvey_tpl_id == 9176281)&lt;br /&gt;
//first org's survey from way up above&lt;br /&gt;
{&lt;br /&gt;
//evt:9452506 should be replaced with the event you created. I have two different &lt;br /&gt;
//surveys. If you only have one, remove the extra coding. &lt;br /&gt;
attached_events_table_record.event_tmpl = &amp;quot;evt:9452506&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
if (zsurvey_tpl_id == 9176283)&lt;br /&gt;
//second org's survey&lt;br /&gt;
{&lt;br /&gt;
attached_events_table_record.event_tmpl = &amp;quot;evt:10224927&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mbraemer</name></author>	</entry>

	<entry>
		<id>http://greggsmith.net/wiki/index.php?title=Send_Survey_based_on_Variables&amp;diff=3540</id>
		<title>Send Survey based on Variables</title>
		<link rel="alternate" type="text/html" href="http://greggsmith.net/wiki/index.php?title=Send_Survey_based_on_Variables&amp;diff=3540"/>
				<updated>2008-11-18T16:40:13Z</updated>
		
		<summary type="html">&lt;p&gt;Mbraemer: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;--[[User:Mbraemer|Mbraemer]] 09:40, 18 November 2008 (MST)&amp;lt;nowiki&amp;gt;Insert non-formatted text here&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
1. First you need to create a request mulitiple notification macro that will be attached to the request. In the &amp;quot;objects&amp;quot; tab, choose affected end user.&lt;br /&gt;
This is the message template from mine. &amp;lt;server_name&amp;gt; should be changed to your url and &amp;lt;survey_template_id&amp;gt; should be changed to the id number of the survey you wish to send out. This will form the link that the user clicks:&lt;br /&gt;
&lt;br /&gt;
@{customer.combo_name} &lt;br /&gt;
You recently contacted the helpdesk about the following issue:&lt;br /&gt;
@{summary}&lt;br /&gt;
Please click on the link below and let us know about your experience&lt;br /&gt;
http://&amp;lt;server_name&amp;gt;/caisd/pdmweb.exe?OP=DO_SURVEY+SID=0+SVY_ID=&amp;lt;survey_template_id&amp;gt;+CNT_ID=@{customer}+CNTXT_PERSID=@{persistent_id}&lt;br /&gt;
&lt;br /&gt;
2. Then add this to an event with no delay or repeat values. in the &amp;quot;Action information&amp;quot; tab, select the multi notification macro in the &amp;quot;actions on true&amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
3. I had to add a field to the survey template table called &amp;quot;zcount&amp;quot; and a field to the contact record called &amp;quot;zlast_survey&amp;quot;&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
MODIFY cr POST_VALIDATE z_survey() 115 FILTER ( status { -&amp;gt; 'CL' });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
cr::z_survey(...) { &lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;Trigger Worked&amp;quot;);&lt;br /&gt;
string zcust_org;&lt;br /&gt;
int zreq_id;&lt;br /&gt;
uuid zcust_id;&lt;br /&gt;
string zreq_persid;&lt;br /&gt;
string zcust_combo;&lt;br /&gt;
string ztype;&lt;br /&gt;
string method;&lt;br /&gt;
object group_leader;&lt;br /&gt;
int do_survey;&lt;br /&gt;
string errmsg;&lt;br /&gt;
int zsurvey_tpl_id;&lt;br /&gt;
&lt;br /&gt;
zcust_org = customer.organization;&lt;br /&gt;
zreq_id = id;&lt;br /&gt;
zcust_id = customer;&lt;br /&gt;
zreq_persid = persistent_id;&lt;br /&gt;
zcust_combo = customer.combo_name;&lt;br /&gt;
ztype = type;&lt;br /&gt;
method = &amp;quot;cr::z_beazer_survey() &amp;quot;;&lt;br /&gt;
do_survey = 0;&lt;br /&gt;
&lt;br /&gt;
//These are just here to log the values to make sure it works. can be removed later&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcust_org=%s&amp;quot;,zcust_org);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zreq_id=%d&amp;quot;,zreq_id);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcust_id=%s&amp;quot;,zcust_id);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zreq_persid=%s&amp;quot;,zreq_persid);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcust_combo=%s&amp;quot;,zcust_combo);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;ztype=%s&amp;quot;,ztype);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//checks to see if customer is in a particular org and the ticket is an incident&lt;br /&gt;
if ( zcust_org == '75D6AB63316EF149B1C3FA5A1390DA40' &amp;amp;&amp;amp; ztype == &amp;quot;I&amp;quot;)&lt;br /&gt;
{&lt;br /&gt;
//this is the survey template id for this org&lt;br /&gt;
zsurvey_tpl_id = 9176281;&lt;br /&gt;
do_survey = 1;&lt;br /&gt;
}&lt;br /&gt;
//checks to see if customer is a in a different org&lt;br /&gt;
if ( zcust_org == 'D08CD8D4DA7C5C48BABB224B5089A93A')&lt;br /&gt;
{&lt;br /&gt;
//this is the template id for this org&lt;br /&gt;
zsurvey_tpl_id = 9176283;&lt;br /&gt;
do_survey = 1;&lt;br /&gt;
}&lt;br /&gt;
//if the org isn't named above,exit code&lt;br /&gt;
if (do_survey == 0)&lt;br /&gt;
{&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
//otherwise, get the survey template object.  &lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;svy_tpl&amp;quot;, &amp;quot;dob_by_id&amp;quot;, 0, zsurvey_tpl_id, NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error in svy_tpl dob_by_id: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
&lt;br /&gt;
object zsurvey_tmpl;&lt;br /&gt;
zsurvey_tmpl=msg[0];&lt;br /&gt;
&lt;br /&gt;
int zoldcount;&lt;br /&gt;
int znewcount;&lt;br /&gt;
int reset_count;&lt;br /&gt;
int ztrk_flag;&lt;br /&gt;
int zcycle;&lt;br /&gt;
string zsurv_sym;&lt;br /&gt;
&lt;br /&gt;
zoldcount = zsurvey_tmpl.zcount;&lt;br /&gt;
ztrk_flag = zsurvey_tmpl.tracking_flag;&lt;br /&gt;
zcycle = zsurvey_tmpl.submit_cycle;&lt;br /&gt;
zsurv_sym = zsurvey_tmpl.sym;&lt;br /&gt;
znewcount = zoldcount +1;&lt;br /&gt;
reset_count = 0;&lt;br /&gt;
&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zoldcount=%d&amp;quot;,zoldcount);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;ztrk_flag=%d&amp;quot;,ztrk_flag);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcycle=%d&amp;quot;,zcycle);&lt;br /&gt;
&lt;br /&gt;
//if stricker rules is selected, this will pull the customer dob and check the last survey field&lt;br /&gt;
if (ztrk_flag == 1){&lt;br /&gt;
//get the customer object&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;cnt&amp;quot;, &amp;quot;dob_by_id&amp;quot;, 0, zcust_id, NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error in cnt dob_by_id: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
object zcustomer_obj;&lt;br /&gt;
zcustomer_obj =msg[0];&lt;br /&gt;
&lt;br /&gt;
date zlast_surv;&lt;br /&gt;
date znow_time;&lt;br /&gt;
duration ztimer;&lt;br /&gt;
&lt;br /&gt;
if (is_null(zcustomer_obj.zlast_survey))&lt;br /&gt;
{zlast_surv = 0;}&lt;br /&gt;
else&lt;br /&gt;
{zlast_surv = zcustomer_obj.zlast_survey;}&lt;br /&gt;
znow_time = now();&lt;br /&gt;
ztimer = znow_time-zlast_surv;&lt;br /&gt;
&lt;br /&gt;
//if last survey was less than 90days ago, exit code&lt;br /&gt;
if (ztimer &amp;lt; 7776000) {&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
//now we need to check the cycle field.&lt;br /&gt;
//get group leader so we can check out the svy tpl object and make changes&lt;br /&gt;
      send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
      if (msg_error()) {&lt;br /&gt;
            errmsg = format(&amp;quot;%s get_co_group error '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
            logf(ERROR, errmsg);&lt;br /&gt;
            set_return_data(errmsg);&lt;br /&gt;
            set_error(1);&lt;br /&gt;
            return -1;&lt;br /&gt;
            }&lt;br /&gt;
group_leader = msg[0];&lt;br /&gt;
&lt;br /&gt;
// check out the sry_tpl obj since we are updating it.&lt;br /&gt;
            send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, zsurvey_tmpl);&lt;br /&gt;
            if (msg_error()) {&lt;br /&gt;
                        errmsg = format(&amp;quot;checkout svy_tpl obj '%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                        logf(ERROR, errmsg);&lt;br /&gt;
                        set_return_data(errmsg);&lt;br /&gt;
                        set_error(1);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                        } &lt;br /&gt;
&lt;br /&gt;
//if the submit cycle number hasn't been reached. add one, check in  and exit code.&lt;br /&gt;
if (znewcount &amp;lt; zcycle){&lt;br /&gt;
send_wait(0, zsurvey_tmpl, &amp;quot;call_attr&amp;quot;, &amp;quot;zcount&amp;quot;, &amp;quot;set_val&amp;quot;, znewcount , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error setting zlast_survey: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
//check the svy_tpl obj in&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
                if (msg_error()) {&lt;br /&gt;
                    errmsg = format(&amp;quot;checkin svy_tpl obj'%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                    logf(ERROR, errmsg);&lt;br /&gt;
                    send_wait(0, group_leader, &amp;quot;uncheck&amp;quot;);&lt;br /&gt;
                    set_return_data(errmsg);&lt;br /&gt;
                      set_error(1);&lt;br /&gt;
                    return -1;&lt;br /&gt;
                    };&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
//else,set the count back to zero and continue through the code&lt;br /&gt;
else {&lt;br /&gt;
send_wait(0, zsurvey_tmpl, &amp;quot;call_attr&amp;quot;, &amp;quot;zcount&amp;quot;, &amp;quot;set_val&amp;quot;, reset_count , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error setting zlast_survey: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
//check the svy_tpl obj in&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
                if (msg_error()) {&lt;br /&gt;
                    errmsg = format(&amp;quot;checkin svy_tpl obj'%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                    logf(ERROR, errmsg);&lt;br /&gt;
                    send_wait(0, group_leader, &amp;quot;uncheck&amp;quot;);&lt;br /&gt;
                    set_return_data(errmsg);&lt;br /&gt;
                      set_error(1);&lt;br /&gt;
                    return -1;&lt;br /&gt;
                    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//this bit of code only fires if stricker rules if enforced&lt;br /&gt;
//we get the customer obj, reset the last survey field to now.&lt;br /&gt;
if (ztrk_flag == 1) {&lt;br /&gt;
// get a group leader so can make changes to the customer obj&lt;br /&gt;
      send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
      if (msg_error()) {&lt;br /&gt;
            errmsg = format(&amp;quot;%s get_co_group error '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
            logf(ERROR, errmsg);&lt;br /&gt;
            set_return_data(errmsg);&lt;br /&gt;
            set_error(1);&lt;br /&gt;
            return -1;&lt;br /&gt;
            }&lt;br /&gt;
group_leader = msg[0];&lt;br /&gt;
&lt;br /&gt;
// check out the customer obj since we are updating it.&lt;br /&gt;
            send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, zcustomer_obj);&lt;br /&gt;
            if (msg_error()) {&lt;br /&gt;
                        errmsg = format(&amp;quot;checkout customer obj '%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                        logf(ERROR, errmsg);&lt;br /&gt;
                        set_return_data(errmsg);&lt;br /&gt;
                        set_error(1);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                        } &lt;br /&gt;
//set the zlast_survey field to now&lt;br /&gt;
send_wait(0, zcustomer_obj, &amp;quot;call_attr&amp;quot;, &amp;quot;zlast_survey&amp;quot;, &amp;quot;set_val&amp;quot;, znow_time , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error setting zlast_survey: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
//check the customer obj in&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
                if (msg_error()) {&lt;br /&gt;
                    errmsg = format(&amp;quot;checkin customer obj'%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                    logf(ERROR, errmsg);&lt;br /&gt;
                    send_wait(0, group_leader, &amp;quot;uncheck&amp;quot;);&lt;br /&gt;
                    set_return_data(errmsg);&lt;br /&gt;
                      set_error(1);&lt;br /&gt;
                    return -1;&lt;br /&gt;
                    }&lt;br /&gt;
 &lt;br /&gt;
//Now, create a surrvey tracking record. This prevents survey from being filled out more than once&lt;br /&gt;
object survey_track_record;&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error getting group leader: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
group_leader = msg[0]; &lt;br /&gt;
&lt;br /&gt;
send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;svytrk&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error creating new svytrk ob: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
survey_track_record = msg[0]; &lt;br /&gt;
&lt;br /&gt;
survey_track_record.tplid = zsurvey_tpl_id;&lt;br /&gt;
survey_track_record.cntid = zcust_id;&lt;br /&gt;
survey_track_record.object_type = &amp;quot;cr&amp;quot;;&lt;br /&gt;
survey_track_record.object_id = zreq_id;&lt;br /&gt;
survey_track_record.notif_dt = znow_time;&lt;br /&gt;
&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//regardless if stricker rules is selected or not, we need to add a survey sent activity record&lt;br /&gt;
&lt;br /&gt;
object activity_log_record;&lt;br /&gt;
string zalg_descr;&lt;br /&gt;
&lt;br /&gt;
//this will format the description like the ones I saw in the activity log&lt;br /&gt;
zalg_descr = format(&amp;quot;Survey Request ('%s') sent to %s&amp;quot;, zsurv_sym,zcust_combo);&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error getting group leader: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
group_leader = msg[0]; &lt;br /&gt;
&lt;br /&gt;
send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;alg&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error creating new alg ob: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
activity_log_record = msg[0]; &lt;br /&gt;
&lt;br /&gt;
activity_log_record.call_req_id = zreq_persid;&lt;br /&gt;
//this is the system ahd contact record id.&lt;br /&gt;
activity_log_record.analyst = &amp;quot;793ED69B4E87A545BD8E911834D829FC&amp;quot;;&lt;br /&gt;
activity_log_record.description = zalg_descr;&lt;br /&gt;
activity_log_record.action_desc = zalg_descr;&lt;br /&gt;
activity_log_record.type = &amp;quot;SRVY_SENT&amp;quot;;&lt;br /&gt;
activity_log_record.internal = 0;&lt;br /&gt;
&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
//finally, attach the event that sends out the message with the link&lt;br /&gt;
object attached_events_table_record;&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;zalglog () - Attach Event: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
group_leader = msg[0]; &lt;br /&gt;
&lt;br /&gt;
send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;atev&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;error attaching event '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
}&lt;br /&gt;
attached_events_table_record = msg[0]; &lt;br /&gt;
attached_events_table_record.obj_id = zreq_persid;&lt;br /&gt;
if (zsurvey_tpl_id == 9176281)&lt;br /&gt;
//first org's survey from way up above&lt;br /&gt;
{&lt;br /&gt;
//evt:9452506 should be replaced with the event you created. I have two different &lt;br /&gt;
//surveys. If you only have one, remove the extra coding. &lt;br /&gt;
attached_events_table_record.event_tmpl = &amp;quot;evt:9452506&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
if (zsurvey_tpl_id == 9176283)&lt;br /&gt;
//second org's survey&lt;br /&gt;
{&lt;br /&gt;
attached_events_table_record.event_tmpl = &amp;quot;evt:10224927&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>Mbraemer</name></author>	</entry>

	<entry>
		<id>http://greggsmith.net/wiki/index.php?title=Send_Survey_based_on_Variables&amp;diff=3539</id>
		<title>Send Survey based on Variables</title>
		<link rel="alternate" type="text/html" href="http://greggsmith.net/wiki/index.php?title=Send_Survey_based_on_Variables&amp;diff=3539"/>
				<updated>2008-11-18T16:37:38Z</updated>
		
		<summary type="html">&lt;p&gt;Mbraemer: How to send a survey based on variables in a request / Incident ticket&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;1. First you need to create a request mulitiple notification macro that will be attached to the request. In the &amp;quot;objects&amp;quot; tab, choose affected end user.&lt;br /&gt;
This is the message template from mine. &amp;lt;server_name&amp;gt; should be changed to your url and &amp;lt;survey_template_id&amp;gt; should be changed to the id number of the survey you wish to send out. This will form the link that the user clicks:&lt;br /&gt;
&lt;br /&gt;
@{customer.combo_name} &lt;br /&gt;
You recently contacted the helpdesk about the following issue:&lt;br /&gt;
@{summary}&lt;br /&gt;
Please click on the link below and let us know about your experience&lt;br /&gt;
http://&amp;lt;server_name&amp;gt;/caisd/pdmweb.exe?OP=DO_SURVEY+SID=0+SVY_ID=&amp;lt;survey_template_id&amp;gt;+CNT_ID=@{customer}+CNTXT_PERSID=@{persistent_id}&lt;br /&gt;
&lt;br /&gt;
2. Then add this to an event with no delay or repeat values. in the &amp;quot;Action information&amp;quot; tab, select the multi notification macro in the &amp;quot;actions on true&amp;quot; section.&lt;br /&gt;
&lt;br /&gt;
3. I had to add a field to the survey template table called &amp;quot;zcount&amp;quot; and a field to the contact record called &amp;quot;zlast_survey&amp;quot;&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
MODIFY cr POST_VALIDATE z_survey() 115 FILTER ( status { -&amp;gt; 'CL' });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
cr::z_survey(...) { &lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;Trigger Worked&amp;quot;);&lt;br /&gt;
string zcust_org;&lt;br /&gt;
int zreq_id;&lt;br /&gt;
uuid zcust_id;&lt;br /&gt;
string zreq_persid;&lt;br /&gt;
string zcust_combo;&lt;br /&gt;
string ztype;&lt;br /&gt;
string method;&lt;br /&gt;
object group_leader;&lt;br /&gt;
int do_survey;&lt;br /&gt;
string errmsg;&lt;br /&gt;
int zsurvey_tpl_id;&lt;br /&gt;
&lt;br /&gt;
zcust_org = customer.organization;&lt;br /&gt;
zreq_id = id;&lt;br /&gt;
zcust_id = customer;&lt;br /&gt;
zreq_persid = persistent_id;&lt;br /&gt;
zcust_combo = customer.combo_name;&lt;br /&gt;
ztype = type;&lt;br /&gt;
method = &amp;quot;cr::z_beazer_survey() &amp;quot;;&lt;br /&gt;
do_survey = 0;&lt;br /&gt;
&lt;br /&gt;
//These are just here to log the values to make sure it works. can be removed later&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcust_org=%s&amp;quot;,zcust_org);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zreq_id=%d&amp;quot;,zreq_id);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcust_id=%s&amp;quot;,zcust_id);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zreq_persid=%s&amp;quot;,zreq_persid);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcust_combo=%s&amp;quot;,zcust_combo);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;ztype=%s&amp;quot;,ztype);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//checks to see if customer is in a particular org and the ticket is an incident&lt;br /&gt;
if ( zcust_org == '75D6AB63316EF149B1C3FA5A1390DA40' &amp;amp;&amp;amp; ztype == &amp;quot;I&amp;quot;)&lt;br /&gt;
{&lt;br /&gt;
//this is the survey template id for this org&lt;br /&gt;
zsurvey_tpl_id = 9176281;&lt;br /&gt;
do_survey = 1;&lt;br /&gt;
}&lt;br /&gt;
//checks to see if customer is a in a different org&lt;br /&gt;
if ( zcust_org == 'D08CD8D4DA7C5C48BABB224B5089A93A')&lt;br /&gt;
{&lt;br /&gt;
//this is the template id for this org&lt;br /&gt;
zsurvey_tpl_id = 9176283;&lt;br /&gt;
do_survey = 1;&lt;br /&gt;
}&lt;br /&gt;
//if the org isn't named above,exit code&lt;br /&gt;
if (do_survey == 0)&lt;br /&gt;
{&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
//otherwise, get the survey template object.  &lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;svy_tpl&amp;quot;, &amp;quot;dob_by_id&amp;quot;, 0, zsurvey_tpl_id, NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error in svy_tpl dob_by_id: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
&lt;br /&gt;
object zsurvey_tmpl;&lt;br /&gt;
zsurvey_tmpl=msg[0];&lt;br /&gt;
&lt;br /&gt;
int zoldcount;&lt;br /&gt;
int znewcount;&lt;br /&gt;
int reset_count;&lt;br /&gt;
int ztrk_flag;&lt;br /&gt;
int zcycle;&lt;br /&gt;
string zsurv_sym;&lt;br /&gt;
&lt;br /&gt;
zoldcount = zsurvey_tmpl.zcount;&lt;br /&gt;
ztrk_flag = zsurvey_tmpl.tracking_flag;&lt;br /&gt;
zcycle = zsurvey_tmpl.submit_cycle;&lt;br /&gt;
zsurv_sym = zsurvey_tmpl.sym;&lt;br /&gt;
znewcount = zoldcount +1;&lt;br /&gt;
reset_count = 0;&lt;br /&gt;
&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zoldcount=%d&amp;quot;,zoldcount);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;ztrk_flag=%d&amp;quot;,ztrk_flag);&lt;br /&gt;
logf(SIGNIFICANT,&amp;quot;zcycle=%d&amp;quot;,zcycle);&lt;br /&gt;
&lt;br /&gt;
//if stricker rules is selected, this will pull the customer dob and check the last survey field&lt;br /&gt;
if (ztrk_flag == 1){&lt;br /&gt;
//get the customer object&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;cnt&amp;quot;, &amp;quot;dob_by_id&amp;quot;, 0, zcust_id, NULL, NULL);&lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error in cnt dob_by_id: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
object zcustomer_obj;&lt;br /&gt;
zcustomer_obj =msg[0];&lt;br /&gt;
&lt;br /&gt;
date zlast_surv;&lt;br /&gt;
date znow_time;&lt;br /&gt;
duration ztimer;&lt;br /&gt;
&lt;br /&gt;
if (is_null(zcustomer_obj.zlast_survey))&lt;br /&gt;
{zlast_surv = 0;}&lt;br /&gt;
else&lt;br /&gt;
{zlast_surv = zcustomer_obj.zlast_survey;}&lt;br /&gt;
znow_time = now();&lt;br /&gt;
ztimer = znow_time-zlast_surv;&lt;br /&gt;
&lt;br /&gt;
//if last survey was less than 90days ago, exit code&lt;br /&gt;
if (ztimer &amp;lt; 7776000) {&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
//now we need to check the cycle field.&lt;br /&gt;
//get group leader so we can check out the svy tpl object and make changes&lt;br /&gt;
      send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
      if (msg_error()) {&lt;br /&gt;
            errmsg = format(&amp;quot;%s get_co_group error '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
            logf(ERROR, errmsg);&lt;br /&gt;
            set_return_data(errmsg);&lt;br /&gt;
            set_error(1);&lt;br /&gt;
            return -1;&lt;br /&gt;
            }&lt;br /&gt;
group_leader = msg[0];&lt;br /&gt;
&lt;br /&gt;
// check out the sry_tpl obj since we are updating it.&lt;br /&gt;
            send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, zsurvey_tmpl);&lt;br /&gt;
            if (msg_error()) {&lt;br /&gt;
                        errmsg = format(&amp;quot;checkout svy_tpl obj '%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                        logf(ERROR, errmsg);&lt;br /&gt;
                        set_return_data(errmsg);&lt;br /&gt;
                        set_error(1);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                        } &lt;br /&gt;
&lt;br /&gt;
//if the submit cycle number hasn't been reached. add one, check in  and exit code.&lt;br /&gt;
if (znewcount &amp;lt; zcycle){&lt;br /&gt;
send_wait(0, zsurvey_tmpl, &amp;quot;call_attr&amp;quot;, &amp;quot;zcount&amp;quot;, &amp;quot;set_val&amp;quot;, znewcount , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error setting zlast_survey: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
//check the svy_tpl obj in&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
                if (msg_error()) {&lt;br /&gt;
                    errmsg = format(&amp;quot;checkin svy_tpl obj'%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                    logf(ERROR, errmsg);&lt;br /&gt;
                    send_wait(0, group_leader, &amp;quot;uncheck&amp;quot;);&lt;br /&gt;
                    set_return_data(errmsg);&lt;br /&gt;
                      set_error(1);&lt;br /&gt;
                    return -1;&lt;br /&gt;
                    };&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
//else,set the count back to zero and continue through the code&lt;br /&gt;
else {&lt;br /&gt;
send_wait(0, zsurvey_tmpl, &amp;quot;call_attr&amp;quot;, &amp;quot;zcount&amp;quot;, &amp;quot;set_val&amp;quot;, reset_count , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error setting zlast_survey: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
//check the svy_tpl obj in&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
                if (msg_error()) {&lt;br /&gt;
                    errmsg = format(&amp;quot;checkin svy_tpl obj'%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                    logf(ERROR, errmsg);&lt;br /&gt;
                    send_wait(0, group_leader, &amp;quot;uncheck&amp;quot;);&lt;br /&gt;
                    set_return_data(errmsg);&lt;br /&gt;
                      set_error(1);&lt;br /&gt;
                    return -1;&lt;br /&gt;
                    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//this bit of code only fires if stricker rules if enforced&lt;br /&gt;
//we get the customer obj, reset the last survey field to now.&lt;br /&gt;
if (ztrk_flag == 1) {&lt;br /&gt;
// get a group leader so can make changes to the customer obj&lt;br /&gt;
      send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;);&lt;br /&gt;
      if (msg_error()) {&lt;br /&gt;
            errmsg = format(&amp;quot;%s get_co_group error '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
            logf(ERROR, errmsg);&lt;br /&gt;
            set_return_data(errmsg);&lt;br /&gt;
            set_error(1);&lt;br /&gt;
            return -1;&lt;br /&gt;
            }&lt;br /&gt;
group_leader = msg[0];&lt;br /&gt;
&lt;br /&gt;
// check out the customer obj since we are updating it.&lt;br /&gt;
            send_wait(0, group_leader, &amp;quot;checkout&amp;quot;, zcustomer_obj);&lt;br /&gt;
            if (msg_error()) {&lt;br /&gt;
                        errmsg = format(&amp;quot;checkout customer obj '%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                        logf(ERROR, errmsg);&lt;br /&gt;
                        set_return_data(errmsg);&lt;br /&gt;
                        set_error(1);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                        } &lt;br /&gt;
//set the zlast_survey field to now&lt;br /&gt;
send_wait(0, zcustomer_obj, &amp;quot;call_attr&amp;quot;, &amp;quot;zlast_survey&amp;quot;, &amp;quot;set_val&amp;quot;, znow_time , &amp;quot;SURE_SET&amp;quot;); &lt;br /&gt;
if ( msg_error()) {&lt;br /&gt;
          errmsg=format(&amp;quot;Error setting zlast_survey: '%s'&amp;quot;,msg[0]);&lt;br /&gt;
          logf(ERROR,method+errmsg);&lt;br /&gt;
          set_return_data(errmsg);&lt;br /&gt;
          set_error(-1);&lt;br /&gt;
          return -1;&lt;br /&gt;
          }&lt;br /&gt;
//check the customer obj in&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
                if (msg_error()) {&lt;br /&gt;
                    errmsg = format(&amp;quot;checkin customer obj'%s' '%s'&amp;quot;, method, msg[0]);&lt;br /&gt;
                    logf(ERROR, errmsg);&lt;br /&gt;
                    send_wait(0, group_leader, &amp;quot;uncheck&amp;quot;);&lt;br /&gt;
                    set_return_data(errmsg);&lt;br /&gt;
                      set_error(1);&lt;br /&gt;
                    return -1;&lt;br /&gt;
                    }&lt;br /&gt;
 &lt;br /&gt;
//Now, create a surrvey tracking record. This prevents survey from being filled out more than once&lt;br /&gt;
object survey_track_record;&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error getting group leader: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
group_leader = msg[0]; &lt;br /&gt;
&lt;br /&gt;
send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;svytrk&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error creating new svytrk ob: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
survey_track_record = msg[0]; &lt;br /&gt;
&lt;br /&gt;
survey_track_record.tplid = zsurvey_tpl_id;&lt;br /&gt;
survey_track_record.cntid = zcust_id;&lt;br /&gt;
survey_track_record.object_type = &amp;quot;cr&amp;quot;;&lt;br /&gt;
survey_track_record.object_id = zreq_id;&lt;br /&gt;
survey_track_record.notif_dt = znow_time;&lt;br /&gt;
&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//regardless if stricker rules is selected or not, we need to add a survey sent activity record&lt;br /&gt;
&lt;br /&gt;
object activity_log_record;&lt;br /&gt;
string zalg_descr;&lt;br /&gt;
&lt;br /&gt;
//this will format the description like the ones I saw in the activity log&lt;br /&gt;
zalg_descr = format(&amp;quot;Survey Request ('%s') sent to %s&amp;quot;, zsurv_sym,zcust_combo);&lt;br /&gt;
&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error getting group leader: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
group_leader = msg[0]; &lt;br /&gt;
&lt;br /&gt;
send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;alg&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;Error creating new alg ob: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
activity_log_record = msg[0]; &lt;br /&gt;
&lt;br /&gt;
activity_log_record.call_req_id = zreq_persid;&lt;br /&gt;
//this is the system ahd contact record id.&lt;br /&gt;
activity_log_record.analyst = &amp;quot;793ED69B4E87A545BD8E911834D829FC&amp;quot;;&lt;br /&gt;
activity_log_record.description = zalg_descr;&lt;br /&gt;
activity_log_record.action_desc = zalg_descr;&lt;br /&gt;
activity_log_record.type = &amp;quot;SRVY_SENT&amp;quot;;&lt;br /&gt;
activity_log_record.internal = 0;&lt;br /&gt;
&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
//finally, attach the event that sends out the message with the link&lt;br /&gt;
object attached_events_table_record;&lt;br /&gt;
send_wait(0, top_object(), &amp;quot;get_co_group&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;zalglog () - Attach Event: error '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
group_leader = msg[0]; &lt;br /&gt;
&lt;br /&gt;
send_wait( 0, top_object(), &amp;quot;call_attr&amp;quot;, &amp;quot;atev&amp;quot;, &amp;quot;get_new_dob&amp;quot;, NULL, NULL, group_leader); &lt;br /&gt;
&lt;br /&gt;
if (msg_error()) { &lt;br /&gt;
logf(ERROR, &amp;quot;error attaching event '%s'&amp;quot;, msg[0]); &lt;br /&gt;
return; &lt;br /&gt;
}&lt;br /&gt;
attached_events_table_record = msg[0]; &lt;br /&gt;
attached_events_table_record.obj_id = zreq_persid;&lt;br /&gt;
if (zsurvey_tpl_id == 9176281)&lt;br /&gt;
//first org's survey from way up above&lt;br /&gt;
{&lt;br /&gt;
//evt:9452506 should be replaced with the event you created. I have two different &lt;br /&gt;
//surveys. If you only have one, remove the extra coding. &lt;br /&gt;
attached_events_table_record.event_tmpl = &amp;quot;evt:9452506&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
if (zsurvey_tpl_id == 9176283)&lt;br /&gt;
//second org's survey&lt;br /&gt;
{&lt;br /&gt;
attached_events_table_record.event_tmpl = &amp;quot;evt:10224927&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
send_wait(0, group_leader, &amp;quot;checkin&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>Mbraemer</name></author>	</entry>

	</feed>