Populate variable value from one catalog item to variable in another catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 07:12 PM
Hi All,
I need to populate the "IT Date" variable from a Catalog item to the same variable "IT Date" in another catalog item.
Please suggest.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 08:16 PM
this is possible.
you can have onLoad catalog client script + GlideAjax and query RITM table with the current Catalog item name and fetch the variable data and set it.
check this link and you should be able to do that
Populate Variables from Existing RITM in a Catalog Item
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
01-08-2025 08:24 PM
To populate the "IT Date" variable from one catalog item to another in ServiceNow, create a Catalog Client Script on the second catalog item. In the script, use GlideAjax to call a server-side Script Include that retrieves the "IT Date" variable value from the first catalog item. The Script Include uses GlideRecord to query the sc_item_option table for the variable associated with the first catalog item and returns the value. Finally, in the client script, set the retrieved value to the "IT Date" variable using gForm.setValue. Ensure proper ACLs are in place and replace the sys_id of the first catalog item in the client script for accurate data retrieval.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 08:56 PM
Hi @Dileep2 ,
You can make use of onload catalog client script and ajax call like below.
Client script
function onLoad() {
// Replace 'source_ritm_sys_id' with the actual sys_id of the source RITM
var sourceRITM = 'source_ritm_sys_id';
var ga = new GlideAjax('CatalogItemVariableFetcher'); // Script Include to fetch variable value
ga.addParam('sysparm_name', 'getVariableValue');
ga.addParam('sysparm_ritm', sourceRITM);
ga.getXMLAnswer(function(response) {
if (response) {
g_form.setValue('it_date, response); // Set the "IT Date" variable value
}
});
}
Server script:
var CatalogItemVariableFetcher = Class.create();
CatalogItemVariableFetcher.prototype = {
initialize: function() {},
getVariableValue: function() {
var ritmSysId = this.getParameter('sysparm_ritm');
var gr = new GlideRecord('sc_item_option_mtom');
gr.addQuery('request_item', ritmSysId); // Link to the RITM
gr.addQuery('sc_item_option.item_option_new', variableSysID); // replace with variable sys id
gr.query();
if (gr.next()) {
return gr.sc_item_option.value; // Return the value of the variable
}
return '';
},
type: 'CatalogItemVariableFetcher'
};
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------