Hi Ted,
This is a bit more complicated than modifying the copy/template functions as they are not defined in tmplcopy_site. You have to create a new Create Change Order function and add a new spel trigger to call the Attach CHG to CR method when it’s used. This example writes the request persid to the change orders string6 attribute then triggers a spel script to attache the change to the request and copy the requests attachments. Let me know if you have questions about any of the steps.
Thank you cdtj for the update to the z_lrel_copy script!
1. Update detail_cr.htmpl
1.1Find the area of code that has the following.
<form name="frm002">
...
</form>
Directly after this place the following code
<form name="zCOMapping">
<input type="hidden" name="SET.requestor" value="$cst.id">
<input type="hidden" name="requestor_combo_name" value="$cst.combo_name">
<input type="hidden" name="SET.affected_contact" value="$cst.id">
<input type="hidden" name="affected_contact_combo_name" value="$cst.combo_name">
<input type="hidden" name="assignee_combo_name" value="$args.assignee.combo_name">
<input type="hidden" name="SET.assignee" value="$args.assignee">
<input type="hidden" name="KEY.assignee" value="$args.assignee.combo_name">
<input type="hidden" name="group_combo_name" value="$args.group.combo_name">
<input type="hidden" name="SET.group" value="$args.group">
<input type="hidden" name="KEY.group" value="$args.group.combo_name">
<input type="hidden" name="SET.impact" value="$args.impact">
<input type="hidden" name="SET.description" value=<PDM_FMT ESC_STYLE=JS2>" (created from Request $args.ref_num)"</PDM_FMT>>
</form>
1.2 Next find the following code
function detailExtraSaveButtons(generate)
{
var count = 0;
<PDM_IF $ACCESS.FAC_chg == 2 && "$args.change" == "">
if ( cfgUserAuth \> 1 ) {
count++;
if ( generate ) {
<PDM_MACRO NAME=button caption="Create Change Order[!ea]" hotkey_name="Create Change Order[!ea]" id=btnchg
func="detailSave('NEW_CHANGE')" Tooltip="Save and Create Change Order">
}
}
</PDM_IF>
<PDM_IF "$args.problem" == "">
if ( cfgUserAuth \> 1 ) {
count++;
if ( generate ) {
<PDM_MACRO NAME=button caption="Create Incident[!eaI]" hotkey_name="Create Incident[!eaI]" id=ITIL_INCIDENT
func="itil_incident()" Tooltip="Save and Create Incident">
}
}
</PDM_IF>
return count;
}
and change it to
function detailExtraSaveButtons(generate)
{
var count = 0;
<PDM_IF 0>
<PDM_IF $ACCESS.FAC_chg == 2 && "$args.change" == "">
if ( cfgUserAuth \> 1 ) {
count++;
if ( generate ) {
<PDM_MACRO NAME=button caption="Create Change Order[!ea]" hotkey_name="Create Change Order[!ea]" id=btnchg
func="detailSave('NEW_CHANGE')" Tooltip="Save and Create Change Order">
}
}
</PDM_IF>
</PDM_IF>
<PDM_IF "$args.problem" == "">
if ( cfgUserAuth \> 1 ) {
count++;
if ( generate ) {
<PDM_MACRO NAME=button caption="Create Incident[!eaI]" hotkey_name="Create Incident[!eaI]" id=ITIL_INCIDENT
func="itil_incident()" Tooltip="Save and Create Incident">
}
}
</PDM_IF>
<PDM_IF $ACCESS.FAC_chg == 2 && "$args.change" == "">
if ( cfgUserAuth \> 1 ) {
count++;
if ( generate ) {
<PDM_MACRO NAME=button caption="Create Change Order[!ea]" hotkey_name="Create Change[!ea]" id=ZCREATECO
func="zCreateCO()" Tooltip="Save and Create Change Order">
}
}
</PDM_IF>
return count;
}
1.3 Find the following code
<PDM_IF "$prop.form_name_3" != "edit">
if ( typeof parent.createIncident == "boolean" &&
parent.createIncident ) {
if (typeof ahdframeset.workframe == "object")
ahdframeset.workframe.SkipInitialFocus = "1";
<PDM_IF "$prop.MultiTenancy" != "on">
create_new('cr',0,0,0,'PRESET=type:I','INITFROM=frm002');
<PDM_ELSE>
create_new('cr',0,0,0,'PRESET=type:I@@tenant:'+argTenantId,'INITFROM=frm002');
</PDM_IF>
}
</PDM_IF>
parent.createIncident = void(0);
and change it to
<PDM_IF "$prop.form_name_3" != "edit">
if ( typeof parent.createIncident == "boolean" &&
parent.createIncident ) {
if (typeof ahdframeset.workframe == "object")
ahdframeset.workframe.SkipInitialFocus = "1";
<PDM_IF "$prop.MultiTenancy" != "on">
create_new('cr',0,0,0,'PRESET=type:I','INITFROM=frm002');
<PDM_ELSE>
create_new('cr',0,0,0,'PRESET=type:I@@tenant:'+argTenantId,'INITFROM=frm002');
</PDM_IF>
}
if ( typeof parent.createChange == "boolean" &&
parent.createChange ) {
if (typeof ahdframeset.workframe == "object")
ahdframeset.workframe.SkipInitialFocus = "1";
create_new('chg',0,0,0,'PRESET=string6:$args.persistent_id','INITFROM=zCOMapping', '');
}
</PDM_IF>
parent.createIncident = void(0);
parent.createChange = void(0);
1.4 Find the following code
<PDM_IF $ACCESS.FAC_chg == 2 && "$args.change" == "">
if ( cfgUserAuth > 1 ) {
<PDM_MACRO name=button Caption="Create Change Order[!ea]" Func="detailSave('NEW_CHANGE')" hotkey_name="Create Change Order[!ea]" ID=btnchg Tooltip="Save and Create Change Order">
}
</PDM_IF>
and change it to
<PDM_IF 0>
<PDM_IF $ACCESS.FAC_chg == 2 && "$args.change" == "">
if ( cfgUserAuth > 1 ) {
<PDM_MACRO name=button Caption="Create Change Order[!ea]" Func="detailSave('NEW_CHANGE')" hotkey_name="Create Change Order[!ea]" ID=btnchg Tooltip="Save and Create Change Order">
}
</PDM_IF>
</PDM_IF>
2. Add spel files to nx_root/site/mods/magic
2.1 Download cdtj's z_lrel_copy from his post above and extract to nx_root/site/mods/magic
2.2 Create a file named zAttachChangeToRequest.mod with the following contents and place in nx_root/site/mods/magic
MODIFY chg POST_CI zAttachChangeToRequest(persistent_id,string6) 100051 FILTER( string6 {} );
2.3 Create a file named zAttachChangeToRequest.spl with the following contents and place in nx_root/site/mods/magic
chg::zAttachChangeToRequest(...)
{
string method;
method="chg::zAttachChangeToRequest";
logf(SIGNIFICANT, "%s started", method);
int x;
for(x=0; x<argc; x++) {
logf(SIGNIFICANT,"argv[%d]=%s",x,argv[x]);
}
string crPersid, chgPersid, desc;
uuid who;
chgPersid =argv[3];
crPersid =argv[6];
desc = "Change Order ";
send_wait(0,top_object(), "call_attr", "cnt", "current_user_id");
who=msg[0];
send_wait(0, top_object(), "call_attr", "api", "get_object_values", who, chgPersid, 0, "chg_ref_num");
if (msg_error()) {
logf(ERROR, "get_failed %s",msg[0]);
}
else
{
int i;
for (i=0;i<msg_length();i++) {
logf(SIGNIFICANT, "msg[%d]: '%s'", i, msg[i]);
}
desc += msg[1] + " created.";
}
send_wait(0, top_object(), "call_attr", "api", "attach_chg_to_request", who, crPersid, chgPersid, desc);
logf(SIGNIFICANT, "%s ended", method);
object old, new;
send_wait(0, top_object(), "call_attr", "cr", "dob_by_id", 0,
crPersid, NULL);
old = msg[0];
if (msg_error()) {
logf(ERROR, "Error getting location ref: %s", loc_dob);
set_error(1);
return;
}
send_wait(0, top_object(), "call_attr", "chg", "dob_by_id", 0,
chgPersid, NULL);
new = msg[0];
if (msg_error()) {
logf(ERROR, "Error getting location ref: %s", loc_dob);
set_error(1);
return;
}
z_lrel_copy(old, new,
"lrel_attachments_requests", "lrel_attachments_changes",
"cr", "chg",
"attmnt"
);
}