- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2020 10:56 AM
Hi guys,
I'm a bit of a newbie with servicenow. I'm trying to get fields from the catalog item record automatically inserted in the service portal when the request is loaded.
each catalog item record has a field called oladuration with values ranging from 1hr, 4hrs,1day, 2days,1week
I did some research and it seems i need to use GlideAjax to accomplish this task. However, I'm not a developer so i'd appreciate any help with the "script include" code and the "catalog client script" code
This is what I was able to conjure up. It doesn't give any errors but the ola doesn't get populated correctly in the service portal.
Script Include
var GetOladuration = Class.create();
GetOladuration.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getOLA: function(){
var item = new GlideRecord("sc_cat_item");
item.get(this.getParameter('sysparm_oladuration'));
return sc_cat_item.u_oladuration;
},
type: 'GetOladuration'
});
Catalog Client script
function onLoad() {
var getOlaDuration = new GlideAjax('GetOladuration');
getOlaDuration.addParam('sysparm_name', 'getOLA');
getOlaDuration.addParam('sysparm_oladuration',g_form.getValue('sc_cat_item.u_oladuration'));
getOlaDuration.getXML(populateOLAfield);
function populateOLAfield(response){
OLAfield = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_oladuration', OLAfield);
}
}
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2020 05:46 AM
Hi guys,
Thanks for all your help. I was able to resolve the issue. The script below worked for me.
SCRIPT INCLUDE
var getOlaDetail = Class.create();
getOlaDetail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getOLA: function() {
//Get the sys_ID for the call
var callSysID = this.getParameter('sysparm_callSysID');
var gr = new GlideRecord('sc_cat_item');
gr.get(callSysID);
var olaDetail = {};
olaDetail.olaDur = gr.getDisplayValue('u_oladuration');
var json = new JSON();
var data = json.encode(olaDetail);
return data;
},
type: 'getOlaDetail'
});
CLIENT SCRIPT
function onLoad() {
var callSysID = g_form.getUniqueValue();
var ga = new GlideAjax('getOlaDetail');
ga.addParam('sysparm_name','getOLA');
ga.addParam('sysparm_callSysID', callSysID);
ga.getXML(handleResponse);
function handleResponse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = JSON.parse(answer);
g_form.setValue("itd_duration",answer.olaDur);
}}}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2020 11:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2020 11:42 AM
Ok, looks fine. Try this:
Script include:
(I have changed the return to the u_oladuration field on the sc_cat_item table. Make sure that field exists in that table and has valid value)
var GetOladuration = Class.create();
GetOladuration.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getOLA: function () {
var item = new GlideRecord("sc_cat_item");
item.get(this.getParameter('sysparm_oladuration'));
gs.info('item=' + item.u_oladuration.toString())
return item.u_oladuration.toString();
},
type: 'GetOladuration'
});
Catalog client script:
function onLoad() {
var getOlaDuration = new GlideAjax('GetOladuration');
getOlaDuration.addParam('sysparm_name', 'getOLA');
getOlaDuration.addParam('sysparm_oladuration', g_form.getValue('u_oladuration'));
alert("oladuration" + g_form.getValue('u_oladuration'));
getOlaDuration.getXML(populateOLAfield);
function populateOLAfield(response) {
OLAfield = response.responseXML.documentElement.getAttribute("answer");
alert("olafield=" + OLAfield);
g_form.setValue('u_oladuration', OLAfield);
}
}
It will alert in the browser and write to the ServiceNow System log. Can you check both and share results?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2020 12:08 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2020 05:46 AM
Hi guys,
Thanks for all your help. I was able to resolve the issue. The script below worked for me.
SCRIPT INCLUDE
var getOlaDetail = Class.create();
getOlaDetail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getOLA: function() {
//Get the sys_ID for the call
var callSysID = this.getParameter('sysparm_callSysID');
var gr = new GlideRecord('sc_cat_item');
gr.get(callSysID);
var olaDetail = {};
olaDetail.olaDur = gr.getDisplayValue('u_oladuration');
var json = new JSON();
var data = json.encode(olaDetail);
return data;
},
type: 'getOlaDetail'
});
CLIENT SCRIPT
function onLoad() {
var callSysID = g_form.getUniqueValue();
var ga = new GlideAjax('getOlaDetail');
ga.addParam('sysparm_name','getOLA');
ga.addParam('sysparm_callSysID', callSysID);
ga.getXML(handleResponse);
function handleResponse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = JSON.parse(answer);
g_form.setValue("itd_duration",answer.olaDur);
}}}