- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2025 06:26 PM
Hello Everyone,
I am having an issue with regards of fetching the data from variables in sc_req_item table.
So i have a new catalog and one of the variable is a reference table into (sc_req_item)
So the idea is i need to get the variable data in that reference table, I can see that i can able to get some data in req item but for variables it shows undefined.
also addinfo message and g_form.setValue is only working to tech view and not in sp portal view. i add it in info message just to see if i get a data but i will input it in the variable using g_form.setValue but again its only working when i was using in technical view not in sp portal.
I do try to transform this code in script include / onchange script but have same result. Any idea ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2025 07:41 PM
Hi @Jeck Manalo ,
it's not a good practice to use GlideRecord directly in client script
use GlideAjax instead
script include
var GetInforCatalog = Class.create();
GetInforCatalog.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function() {
var res = {
catName: '',
userid: ''
};
var reqItem = new GlideRecord('sc_req_item');
if (reqItem.get(this.getParameter('reqsysid'))) {
res.catName = reqItem.cat_item.getDisplayValue();
res.userid = reqItem.variables.test2 ? reqItem.variables.test2 : '';
// extend your logic here
}
return JSON.stringify(res);
},
type: 'GetInforCatalog'
});
Client script
assuming this on the onchange of the RITM reference variable
var ga = new GlideAjax('GetInforCatalog');
ga.addParam('sysparm_name', 'getDetails');
ga.addParam('reqsysid', newValue);
ga.getXMLAnswer(function(answer) {
alert(answer);
answer = JSON.parse(answer);
g_form.addInfoMessage('Catalog Item Name: ' + answer.catName);
g_form.addInfoMessage('User ID WD: ' + answer.userid);
//add you logic here
})
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2025 07:42 PM
you cannot dot walk variables.variableName in client side
you should not use GlideRecord in client side as it's not recommended.
You can use onChange + GlideAjax and get the variable values
Something like this which I shared solution but please enhance, you can use normal onchange client script instead of catalog client script, but please enhance
How to access ritm variables (variables used in catalog item) using catalog client script?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2025 07:41 PM
Hi @Jeck Manalo ,
it's not a good practice to use GlideRecord directly in client script
use GlideAjax instead
script include
var GetInforCatalog = Class.create();
GetInforCatalog.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function() {
var res = {
catName: '',
userid: ''
};
var reqItem = new GlideRecord('sc_req_item');
if (reqItem.get(this.getParameter('reqsysid'))) {
res.catName = reqItem.cat_item.getDisplayValue();
res.userid = reqItem.variables.test2 ? reqItem.variables.test2 : '';
// extend your logic here
}
return JSON.stringify(res);
},
type: 'GetInforCatalog'
});
Client script
assuming this on the onchange of the RITM reference variable
var ga = new GlideAjax('GetInforCatalog');
ga.addParam('sysparm_name', 'getDetails');
ga.addParam('reqsysid', newValue);
ga.getXMLAnswer(function(answer) {
alert(answer);
answer = JSON.parse(answer);
g_form.addInfoMessage('Catalog Item Name: ' + answer.catName);
g_form.addInfoMessage('User ID WD: ' + answer.userid);
//add you logic here
})
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2025 07:59 PM
Actually i tried the script include already but this code works very well.
Thank you i can now able to fetch the data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2025 07:42 PM
you cannot dot walk variables.variableName in client side
you should not use GlideRecord in client side as it's not recommended.
You can use onChange + GlideAjax and get the variable values
Something like this which I shared solution but please enhance, you can use normal onchange client script instead of catalog client script, but please enhance
How to access ritm variables (variables used in catalog item) using catalog client script?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2025 07:47 PM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader