- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2025 04:10 AM
We have created the following client script on the Shopping Hub checkout record producers. We want to fetch the product short description and autopopulate the part description field using an on-load client script. However, this script is not working on the Shopping Hub portal. When we run this script as a background script, it works properly.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2025 04:34 AM
is part_description a variable on your record producer?
if yes then why not use default value and set it?
javascript: var val;
var gr = new GlideRecord('sn_shop_supplier_product');
gr.addQuery('sys_id', 'd144b0d287fb1e50ef8e0e5e8bbb350c');
gr.query();
if (gr.next()) {
val = gr.getValue('short_description');
}
val;
As per best practices store that sysId in system property and use that if required
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
‎02-25-2025 04:18 AM
Hi @Praju_123
GlideRecord should not be used in client scripts. You can use getRefefence with callback function if 'product' is a reference type variable on your record producer. Or use GlideAjax method with a client callable script include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2025 04:22 AM
Create a client script and script include as mentioned below:
Client script
function onLoad() {
var ga = new GlideAjax('GetProductDescription');
ga.addParam('sysparm_name', 'getDescription');
ga.addParam('sysparm_product_id', 'd144b0d287fb1e50ef8e0e5e8bbb350c');
ga.getXMLAnswer(function(response) {
if (response) {
g_form.setValue('part_description', response);
} else {
g_form.setValue('part_description', 'Description not found');
}
});
}
Script Include:
getDescription: function(productSysId) {
var gr = new GlideRecord('sn_shop_supplier_product');
if (gr.get(productSysId)) {
return gr.short_description;
}
return "No description found";
},
If my response helped please mark it correct and close the thread so that it benefits future readers.
Priyatam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2025 04:34 AM
is part_description a variable on your record producer?
if yes then why not use default value and set it?
javascript: var val;
var gr = new GlideRecord('sn_shop_supplier_product');
gr.addQuery('sys_id', 'd144b0d287fb1e50ef8e0e5e8bbb350c');
gr.query();
if (gr.next()) {
val = gr.getValue('short_description');
}
val;
As per best practices store that sysId in system property and use that if required
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-28-2025 04:25 AM
Hope you are doing good.
Did my reply answer your question?
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