Service portal widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 05:10 AM
Hi I want to pass a value from Client to HTML.
For that I passed from client to server then server to HTML. Showing undefined in Server
HTML:
<a target="_new" href="{{c.data.dataURL}}.do?PDF">
<button>
Test
</button>
</a>
CS:
var canvas = document.getElementById("qrcode");
c.data.dataURL = canvas.toDataURL();
c.img64= function() {
c.server.update();
}
Server:
data.dataURL = input.dataURL;
gs.addInfoMessage(input.dataURL);
. plz help

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 08:27 AM
Hello @Rosy14 ,
you have defined c.img64 as a function which is never called, so the update is never happening hence the undefined.
Here is a short example to illustrate how it works:
HTML:
<div class="panel panel-default b">
<div class="panel-heading">
<div><h2 class="panel-title">{{c.data.dataUrl}}</h2></div>
<button type="button"class="btn btn-danger btn-xs" ng-click="c.clickMe()">Click Me!</button>
</div>
</div>
CS:
api.controller = function () {
/* widget controller */
var c = this;
c.data.dataUrl = "Currently I'm not changed.";
c.clickMe = function () {
console.log("Click!");
c.server.update();
};
};
Server:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
if(input) {
data.dataUrl = "Now I've changed!"
}
})();
Regards, Ivan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 08:39 AM
Hi @Rosy14 ,
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>