Copy RITM Variables to New Catalog Form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 01:55 AM
I'm working on a Service Portal widget that displays "My Requests" and need to implement a Copy functionality for specific catalog items (iPhone 13 Pro). The requirement is:
- Show a "Copy" button beside RITMs for iPhone 13 Pro catalog items ✅ (Working)
- When clicked, redirect to the catalog item form ✅ (Working)
- Auto-populate the new form with variable values from the original RITM ❌ (Not working)
Current Implementation
Widget Client Script (Copy Button)
$scope.copyRequest = function(ritmSysId, catalogItemSysId) { var copyUrl = '/sp?id=sc_cat_item&sys_id=' + catalogItemSysId + '©_from=' + ritmSysId; window.open(copyUrl, '_blank'); };
Widget HTML Template
<div ng-if="item.cat_item_name == 'iPhone 13 Pro'"> <button class="btn btn-primary btn-sm" ng-click="copyRequest(item.sys_id, item.cat_item_sys_id)" title="Copy this request"> <i class="fa fa-copy"></i> Copy </button> </div>
Catalog Item Client Script (onLoad)
function onLoad() { function getParameterByName(name) { var url = window.location.href; name = name.replace(/[\[\]]/g, '\\$&'); var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'); var results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, ' ')); } var ritmId = getParameterByName('copy_from'); if (ritmId) { var ga = new GlideAjax('CatalogPrefillUtil'); ga.addParam('sysparm_name', 'getPrefillData'); ga.addParam('sysparm_ritm_id', ritmId); ga.getXMLAnswer(function(response) { try { console.log('📦 Raw response from GlideAjax:', response); var values = JSON.parse(response); // Set variables here - use exact *Name* of variables (not label!) if (values.monthly_data_allowance) g_form.setValue('monthly_data_allowance', values.monthly_data_allowance); if (values.storage) g_form.setValue('storage', values.storage); } catch (e) { console.error('❌ Error parsing or applying variable values:', e); } }); } }
Script Include (Client Callable)
var CatalogPrefillUtil = Class.create(); CatalogPrefillUtil.prototype = { initialize: function() {}, getPrefillData: function() { var ritmId = gs.getParameter('sysparm_ritm_id'); var result = {}; var ritm = new GlideRecord('sc_req_item'); if (ritm.get(ritmId)) { var vars = ritm.variables; result.monthly_data_allowance = vars.monthly_data_allowance + ''; result.storage = vars.storage + ''; } return JSON.stringify(result); }, type: 'CatalogPrefillUtil' };
Issue Encountered
When I test the Script Include in Scripts - Background:
var util = new CatalogPrefillUtil(); gs.setParameter('sysparm_ritm_id', 'ACTUAL_RITM_SYS_ID'); var result = util.getPrefillData(); gs.log('Test result: ' + result);
Result:
*** Script: 🔍 DEBUG: Starting getPrefillData for RITM: undefined*** Script: ❌ RITM not found: undefined*** Script: 📤 Final result: {"error":"RITM not found"}
The RITM ID is coming through as undefined, suggesting the parameter isn't being passed correctly.
Questions
- What's the correct way to access catalog variables from a RITM record? Is ritm.variables.variable_name the right approach?
- How should I properly retrieve variable values from sc_req_item records? Should I be querying sc_item_option_mtom instead?
- Is there a better way to pass parameters from Service Portal to catalog client scripts?
- Are there any known issues with gs.getParameter() in Script Includes when called from Service Portal?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 05:31 AM
the onload client script will work fine if the URL is correct i.e. redirection is happening
is redirection happening?
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
07-08-2025 05:32 AM
No, when i click on copy no redirection is happening now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 05:18 AM
I know I have given so much to check and process, but I have been trying and working on this solution from past two days, so really want your help on this. Thanks in advance.