TMACUL

http://www.servicedeskusers.com/Refresh_Customer_Info_Before_Saving_the_Ticket.

Blog Post created by TMACUL Champion on Jan 1, 2016

Refresh Customer Info Before Saving the Ticket

From SDU

Jump to: navigation, search

 

To make corrections or additions to this article, select the edit tab above.
To discuss or ask questions about this article, select the discussion tab above.

 

Overview

This article provides customization to detail_in.htmpl for refreshing end user location and phone (as displayed on the form) when the end user changes BEFORE saving the change. The code works, but I am not crazy about it. I am hoping that someone can find a more elegant way to implement the same. I have only implemented and did limited testing in development, so the code has not been tested in the real world environment.

My understanding of the code is very limited, and was gained by trial and error, so my explanation and terminology might not be correct.

There are functions that you can use to call the server, I only mention two of them here: upd_workframe() and display_new_page(). In calls to these functions you can specify a callback function that will receive the results of the server lookup. In this code, I used two calls to display_new_page(): zCustomerLocationCallback() was specified as the callback in the 1st call, and zCustomerPhoneCallback() in the second one.

I encountered a few problems. First, I could not find a way to look up both location and phone in one server call, even though they both would be a lookup of the same record based on the same contact UUID. As a result, I had to do two server calls. Another problem is that if you try to do one server call after another, only the callback that was evoked by the last one will be executed. In other words, if in backfill_cnt_event() I had the following code, I would only see the phone being refreshed:

upd_workframe("GET_SVC_CONTRACT", "new_customer=cnt:" + cntID, "func=parent.ahdframe.get_svc_callback"); display_new_page(url,ahdframeset.workframe); // with url for zCustomerLocationCallback() ….. display_new_page(url,ahdframeset.workframe); // with url for zCustomerPhoneCallback()

That means that if you want to execute more than one callback per event, you have to call the next one from the previous. In this particular scenario, I had to execute 3 callback functions when an end user changes: 
1. Service contract check (upd_workframe("GET_SVC_CONTRACT"..) - out of the box behavior)
2. Location lookup 
3. Phone lookup
So I had to “chain” them: location callback function triggers phone callback, and phone callback triggers Service contract check.

I based my code on nr_inv_tab.htmpl and nr_ops.js: this code causes the manufacturer to be refreshed when the model of the asset changes. zcustomerChanged() is based on ModelChanged(), and the 2 callback functions are based on modelChangedCallback(). The difference is that I could not use onBlur() or on Change(), because I needed contact UUID, not the combo name(there can be duplicates), and it wouldn’t be available there. That’s why I used function

backfill_cnt_event( form_name, base_name, lname, fname, mname, cntID, caller_type )

where cntID is the new contact UUID. Also, I noticed that in nr_inv_tab.htmpl vendor only gets refreshed if the model is selected from the model search window, and not if you type it in and tab out. My code works in both scenarios.

View the Complete Code

Click Here to download the complete code.

Customization Steps

Step 1. Add customer location and phone

Note that Ids are important here - they will be used by the callback functions to refresh the fields.

<PDM_MACRO NAME=dtlReadonly hdr="End User Location" attr="customer.location" id=custloc> <PDM_MACRO NAME=dtlReadonly hdr="End User Phone" attr="customer.phone_number" id=custphone>

Step 2. Modify function backfill_cnt_event() as follows

Comment out (or delete) Contract enforcement code and add a call the new custom function. It will look as follows:

function backfill_cnt_event( form_name, base_name, lname, fname, mname, cntID, caller_type ) { if (_dtl.edit && !_dtl.skip_agt_check) { var f = void(0); var r = form_name.match(/main_form([0-9]*)/); if ( r != null ) { if ( r[1].length == 0 ) f = _dtl.form[0]; else f = _dtl.form[r[1]-0]; } detailAgtCheck(f, base_name, cntID, prop_ref); } detailCntBackfill( form_name, base_name, lname, fname, mname, cntID, caller_type );   // sk: if user org has a service contract, the following code will clear out the category after changing user // if it is not a private category from the contract under the contract, and will display message:  // "The current category can not be used with the current End User. The category has been reset." // Contract enforcement:                   /* if (ahdtop.cfgNX_CLASSIC_SLA_PROCESSING != 'Yes' && base_name == "customer" && typeof cntID != "undefined" && cntID.length > 1) {   upd_workframe("GET_SVC_CONTRACT", "new_customer=cnt:" + cntID, "func=parent.ahdframe.get_svc_callback"); } */ // Note: even if remove "typeof cntID != "undefined" && cntID.length > 1", zRefreshCustomerInfo() still does not get called if (base_name == "customer" && typeof cntID != "undefined" && cntID.length > 1) { zcustomerChanged(form_name, base_name, lname, fname, mname, cntID, caller_type); } }

Step 3. Add the following code at the end of backfill_cnt_event()

if (base_name == "customer" && typeof cntID != "undefined" && cntID.length > 1) { zcustomerChanged(form_name, base_name, lname, fname, mname, cntID, caller_type); }

Step 4. Add the following java script code before function backfill_cnt_event()

var zcurrCustID="";   // Based on modelChanged() in nr_ops.js function zcustomerChanged(form_name, base_name, lname, fname, mname, cntID, caller_type ) { //alert(cntID); //newly selected contact UUID var zFID=document.forms["main_form"].elements["FID"].value; var zSID=document.forms["main_form"].elements["SID"].value; var zcntID=cntID.replace("U",""); zcntID=zcntID.replace("'","");   if (zcurrCustID == zcntID) return; zcurrCustID=cntID;   var url; if(ahdframe.currentAction==0) // =0 if customer selected from contact list; =6 if typed in  { set_action_in_progress(ACTN_AUTOFILL); } url=cfgCgi+"?SID="+zSID+"+FID="+zFID +"+OP=SEARCH+FACTORY=cnt" +"+KEEP.domset_name=RLIST_STATIC" +"+QBE.EQ.id="+escape(zcntID) +"+KEEP.backfill_attr=location.name" +"+HTMPL=javascript:parent.ahdframe.zCustomerLocationCallback"; display_new_page(url,ahdframeset.workframe); if(ahdframe.currentAction==0) // =0 if customer selected from contact list; =6 if typed in  { set_action_in_progress(ACTN_AUTOFILL); } }   // Based on modelChangedCallback() in nr_ops.js function zCustomerLocationCallback(persid,value,rel_attr_val) { set_action_in_progress(0); //alert(persid); // cnt UUID with "cnt:" prefix //alert(rel_attr_val); // cnt UUID without "cnt:" prefix //alert(value); // location name var e=document.getElementById("custloc"); if(e!=null) e.innerHTML=value;   var zFID=document.forms["main_form"].elements["FID"].value; var zSID=document.forms["main_form"].elements["SID"].value; var url=cfgCgi+"?SID="+zSID+"+FID="+zFID +"+OP=SEARCH+FACTORY=cnt" +"+KEEP.domset_name=RLIST_STATIC" +"+QBE.EQ.id="+escape(rel_attr_val) +"+KEEP.backfill_attr=phone_number" +"+HTMPL=javascript:parent.ahdframe.zCustomerPhoneCallback"; display_new_page(url,ahdframeset.workframe); if(ahdframe.currentAction==0) // =0 if customer selected from contact list; =6 if typed in  { set_action_in_progress(ACTN_AUTOFILL); } }   // Based on modelChangedCallback() in nr_ops.js function zCustomerPhoneCallback(persid,value,rel_attr_val) { set_action_in_progress(0); var e=document.getElementById("custphone"); if(e!=null) e.innerHTML=value;   if (ahdtop.cfgNX_CLASSIC_SLA_PROCESSING != 'Yes') { upd_workframe("GET_SVC_CONTRACT", "new_customer=cnt:" + rel_attr_val, "func=parent.ahdframe.get_svc_callback"); } }

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

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

Outcomes