- 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:18 AM
Hello @nosazena,
Here in line
getOlaDuration.addParam('sysparm_oladuration',g_form.getValue('sc_cat_item.u_oladuration'))
you cannot use "sc_cat_item.u_oladuration",as dot walking is not a best praticse in servicenow client script.
you can pass the field value directly to scrilt include.and apply the filter and script there in script include.
From client script please pass the value entered in field directly.
Please keep posted for more help
Regards
Yash Agrawal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2020 11:19 AM
Make sure your catalog client script is set as UI Type All or Service portal/mobile.
Try change the Catalog client script to:
function onLoad() {
var getOlaDuration = new GlideAjax('GetOladuration');
getOlaDuration.addParam('sysparm_name', 'getOLA');
getOlaDuration.addParam('sysparm_oladuration', g_form.getValue('u_oladuration'));
getOlaDuration.getXML(populateOLAfield);
function populateOLAfield(response) {
OLAfield = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_oladuration', OLAfield);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2020 11:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2020 11:26 AM
Can you share screenshot of your Catalog client script?
Few things to check:
- Is it attached to the Catalog? If not attach it, or attach it to a Variable Set and attach that variable set to the Catalog items you want.
- UI Type set to All or Service portal/mobile.
- You can include logs and alerts to see if any value is retrieved.