UI Page - How to pass value from Client Script to HTML
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 12:59 PM
We have UI Pages included in Homepages that no longer functions on Dashboards.
We need one of the following solutions:
- Find browser (top) URL in HTML so we car parse it for a param
- We can find that in the Client Script. Need method to pass that value as a var in the HTML
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 05:08 AM
Hi @rlatorre ,
To pass a value from a client script to an HTML section of a UI Page, you can use the addParameter() method of the GlideRecord class.
First, in your client script, you can use the g_form.getSysId() method to get the sys_id of the record being displayed. You can then construct the URL for the current page and pass it as a parameter to the UI Page.
Here's an example of how to do this:
var currentSysId = g_form.getSysId();
var currentUrl = window.location.href;
var encodedUrl = encodeURIComponent(currentUrl);
// Pass the current sys_id and URL as parameters to the UI Page
var gr = new GlideRecord('sys_ui_page');
gr.addQuery('name', 'your_ui_page_name');
gr.query(function() {
if (gr.next()) {
gr.addParameter('sysparm_sys_id', currentSysId);
gr.addParameter('sysparm_current_url', encodedUrl);
var iframesrc=gr.getValue('page');
var iframeHtml = '<iframe src="' + iframeSrc + '"></iframe>';
$('#your_div_id').html(iframeHtml);
}
});
Then, in the HTML section of your UI Page, you can access the parameters using the getParameter() method of the GlideURI class. Here's an example of how to do this:
<script>
var sysId = new GlideURI().getParameter('sysparm_sys_id');
var currentUrl = decodeURIComponent(new GlideURI().getParameter('sysparm_current_url'));
// Use the sys_id and URL in your HTML code
// ...
</script>
If my response helps you to resolve the issue close the question by ✅Accepting solution and hit 👍thumb icon. From Correct answers others will get benefited in future.
Thanks,
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2023 08:40 AM
Hi,
We are still having some difficulty.
What does this reference?
var iframesrc=gr.getValue('page');
And how does the div mID work into the HTML?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2023 09:50 AM - edited 04-21-2023 09:54 AM
We see error in browser
Uncaught ReferenceError: GlideURI is not defined
Uncaught TypeError: gr.addParameter is not a function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 08:10 AM - edited 03-16-2023 08:11 AM
I'm sure I made a mistake but getting these errors:
For background, we were linking to a UI Page with a param in the URL:
/now/nav/ui/classic/params/target/ui_page.do%3Fsys_id%3D7b4e6d90a4d4954000e5bc477cdbe656%26sysparm_mi%3DINC3274790
Before switching to Next Experience, we used this in the HTML to extract the param:
RP.getParameterValue('sysparm_this_url').split('sysparm_mi=')[1].substr(0,10);
After switching to Next Experience, it did not work. I believe it was only seeing "angular.do"
I was able to extract the param in the Client Script which is why I asked the question.
var currentIncNum = window.top.location.toString().split('sysparm_mi')[1].substr(3, 13);
Since we have the param in the URL opening the UI Page, how best can we extract that data in Next Experience?
Thank you very much for this assistance!!!!