UI Action to auto navigate to record producer passing values in URL - not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 12:44 PM
I have a ui action that calls a record producer and passes a value to one of the variables and launches the record producer. Attempting to auto-populate a variable onLoad from variables/values available in the ritm/sc_task tables.
I am getting an error message when the record producer's onLoad Client script is called:
ReferenceError: RP is not defined
at presetFields (com.glideapp.service…sset_manager:865:15)
at onLoad_57060aeb87b40610739742e8cebb35bb (com.glideapp.service…asset_manager:870:1)
at com.glideapp.service…asset_manager:877:1
at js_includes_doctype.jsx:557:4
at runBeforeRender (js_includes_doctype.jsx:474:5)
at z_last_include.jsx:33:2
at z_last_include.jsx:39:3
-------------------------------
UI Action:
The url it generates is: /com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=1297d75ba1617010fa9b20d39126489f&sysparm_requested_by=asset_manager
Any help much appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 11:47 PM
Hi,
Use this code in client script
function onLoad() {
var reqBy = getParameterValue('sysparm_requested_by');
g_form.setValue('requested_by', reqBy);
}
function getParameterValue(name) {
var url = top.location.href;
var value = new URLSearchParams(url).get(name);
if (value) {
return value;
}
if (!value) {
var gUrl = new GlideURL();
gUrl.setFromCurrent();
value = gUrl.getParam("sysparm_id");
return value;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2024 12:00 AM
Hi @CA7
Can you modify the client script and UI Action script as follows-
onLoad Client Script-
function presetFields() {
// Use g_form.getParameter() to access URL parameters
var reqBy = g_form.getParameter('sysparm_requested_by');
// Check if the parameter exists and is not null
if (reqBy) {
// Use g_form.setValue() to set the field value
g_form.setValue('requested_by', reqBy);
}
}
// Call the function to preset fields when the form loads
presetFields();
UI Action-
var reqBy = 'asset_manager';
var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=1297d75ba1617010fa9b20d39126489f';
url += '&sysparm_requested_by=' + reqBy;
g_navigation.open(url, '_blank');