Pass variable from HTML to client script in UIpage
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2023 05:50 AM
Hi Folks,
I am calling a UI page from UI action and passing some info to the page. I need to pass this from html to client script of UI page. I tried it using the below script but it is not working....
HTML-
<g:evaluate jelly="true">
var id = RP.getWindowProperties().get('sys_id');
var fname = RP.getWindowProperties().get('file_name');
</g:evaluate>
<button onclick = 'fnExcelReport(fname)'>Export to Excel</button>
Client script -
function fnExcelReport(file_name){
alert(file_name)
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2023 06:05 AM
Hi @Tapish Sharma1 ,
To pass a variable from HTML to client script in a UI page, you can modify your code as follows:
HTML:
<g:evaluate jelly="true">
var id = RP.getWindowProperties().get('sys_id');
var fname = RP.getWindowProperties().get('file_name');
// Call the client script function with the variable
fnExcelReport(fname);
</g:evaluate>
<button onclick="fnExcelReport(fname)">Export to Excel</button>
Client Script:
function fnExcelReport(file_name) {
alert(file_name);
}
In this code, the <g:evaluate> tag evaluates the Jelly script and assigns the fname variable. Then, the client script function fnExcelReport() is called immediately after assigning the variable in the HTML. This way, the fname variable is accessible in the client script.
Make sure that the HTML and client script are properly included in your UI page and that the function fnExcelReport() is defined in your client script.
Note: If you are using a scoped application, ensure that you have the necessary script includes or dependencies included in your UI page to load the required client script functions.
If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the ✅Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.
Thank you!
Ratnakar
