How to Populate values from Interaction to Service catalog item?

Prasanna Kumar
Giga Contributor

Hi Team,
How do we populate values from Interaction table to Service catalog item?
Situation: We have field Call type = "Request" on Interaction table, when ever selection "Request", "Request Item (Reference of cat_item table). I've created a BR on Interaction table, and trying to populate the values from Interaction to Catalog item variables. I used the attached script in BR, Script include and Client script for the same.

Please review and let us know how do we populate values.
Thanks & Regards,
Prasanna Duvvuri

Can't able to attach so, pasted the scripts below:
Related scripts:
Business Rule:
Name: Interaction - Creating Service Request
Table: u_interaction
When to Run: After Insert/Update
Conditions: Calltype changes to Request
Script:
(function executeRule(current, previous /*null when async*/ ) {
var url;
var reqItem = current.u_request_item;
var reqFor = current.u_requested_for;
var intNo = current.sys_id;
gs.addInfoMessage("activeCatalogsCount---->"+intNo);
var comments = "NEW_CALL_REF:" + current.sys_id + " " + current.description;
gs.addInfoMessage("activeCatalogsCount---->"+comments);
getCart();

url = '/com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=' + reqItem + '&sysparm_callSYSID=' + intNo;
action.setRedirectURL(url);
function getCart() {
var cart = new GlideRecord('sc_cart');
var userid = gs.getUserID();
cart.addQuery('user', userid);
cart.query();
if (cart.next()) {
cart.requested_for = reqFor;
cart.special_instructions = comments;
//cart.delivery_address = '';
cart.update();
var cartItems = new GlideRecord('sc_cart_item');
cartItems.addQuery('cart', cart.sys_id);
cartItems.deleteMultiple();
} else {
cart.initialize();
cart.user = userid;
cart.requested_for = reqFor;
cart.special_instructions = comments;
//cart.delivery_address = '';
cart.insert();
}
return cart;
}
})(current, previous);

Script Include:
Name: getInfoFromCall
Client Callable: True
Script:
var getInfoFromCall = Class.create();
getInfoFromCall.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getNewCallValues: function() {
var callSysID = this.getParameter('sysparm_callSysID');
gs.log("$$$$ScriptInclude New Call SYSID: "+callSysID);
var gr = new GlideRecord('u_interaction');
gr.addQuery('sys_id',callSysID);
gr.query();
if(gr.next()){
var description = gr.description;
//var reqFor = gr.getDisplayValue('u_requested_for');
//var shortDesc = gr.getDisplayValue('short_description');
var intSYSID = gr.sys_id;
gs.log("$$$$ScriptInclude: "+intSYSID);
return description+'||'+intSYSID;//'||'+reqFor+'||'+shortDesc+'
}
},
type: 'getInfoFromCall'
});

Client Script:
Name: Populate Variables from Interaction
Type: OnLoad
Script:
var callSysID = getParmVal('sysparm_callSYSID'); alert(callSysID);
var ga = new GlideAjax('getInfoFromCall');
ga.addParam('sysparm_name', 'getNewCallValues');
ga.addParam('sysparm_callSysID', callSysID);
ga.getXML(handleResponse);
function handleResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var result = answer.split("||");
alert(result[0]+"---->"+result[1]);
g_form.setValue('interaction_comments', result[0]);
//g_form.setValue('requested_for', result[1]);
//g_form.setValue('u_summary', result[2]);
g_form.setValue('interaction_number', result[1]);
}

}
function getParmVal(name) {
var url = document.URL.parseQuery();
if (url[name]) {
return decodeURI(url[name]);
} else {
return;
}
}

2 REPLIES 2

Community Alums
Not applicable

HI @Prasanna Kumar ,

Refer below links for help

Passing variables from interaction record ti catalog item in Agent Workspace

Passing variables from interatcion record to catalog item in Agent Workspace

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

Thank you @Sandeep Dutta, Thank you for your quick reply. Here, I'm not using Interaction plugin, it is a Customized table and please let me know, is the local storage is working for customized tables. If yes, please let me know, so that I'll try the local storage for the same.

Also, please let me know how to modify the BR and Client script with Local storage script.

 

Thanks & Regards,

Prasanna Kumar