How do I get the dynamic values in ui page like serial no.. etc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 03:41 AM - edited 02-27-2024 02:51 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 05:48 AM
Are you asking how to pass dynamic variables to the loaded ui page or how to access the answers provided in fields on the ui page in the client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 10:35 PM
Hi Kristen,
Let me explain you more clearly, I have a Ui page and there is ui action in alm_hardware named generate_pdf which is download the ui page in pdf.
Now my requirement is to get a dynamic value in my ui page like the serial no is present in alm_hardware form is automatically fetched in my ui page so that When i download it will shows there....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 05:20 AM
When you ui action calls your UI page, you will use GlideModal to call that UI Page. In that, you can use "setPreference" which has two attributes: the name of the variable you'll access on the UI page (standard is to start with sysparm_) and the second is the value you want to pass. On the UI page, in the HTML, you will then use the syntax RP.getParameterValue('sysparm_your_variable'). Depending on where you call this in the HTML, you might need to add a "${}" or "$[]" around it to get the value.
GlideModal documentation:
https://developer.servicenow.com/dev.do#!/reference/api/utah/client/c_GlideModalV3API?navFilter=mod
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 12:07 AM
Hi @Aman Trivedi1 ,
To dynamically populate values from the alm_hardware record into your UI page before generating the PDF, you would typically need to perform a GlideRecord query in the UI action script to retrieve the necessary data and then pass it to the UI page for rendering.
Here's a general outline of how you can achieve this:
- Modify your UI action script (generate_pdf) in the alm_hardware table to perform a GlideRecord query to retrieve the relevant record.
- Extract the required values (e.g., serial number) from the retrieved record.
- Pass these values to your UI page template using Jelly variables or scriptlets.
- Use these variables or scriptlets to dynamically populate the corresponding fields in your UI page template.
Below is an example of how you can modify your UI action script to achieve this:
UI Action Script
(function execute(parameters) {
// Define the sys_id of the hardware record
var hardwareSysId = current.sys_id; // Assuming current refers to the current hardware record
// Perform a GlideRecord query to retrieve the hardware record
var hardwareGR = new GlideRecord('alm_hardware');
if (hardwareGR.get(hardwareSysId)) {
// Extract the required values from the hardware record
var serialNumber = hardwareGR.serial_number.toString(); // Assuming 'serial_number' is the field name
// Pass the extracted values to the UI page template
var redirectURL = '/your_ui_page.jsp?' + GlideStringUtil.urlEncode({
sysparm_sno: serialNumber // Assign serial number to sysparm_sno parameter for passing to the UI page
});
// Redirect to the UI page with the parameters
action.setRedirectURL(redirectURL); // Replace 'your_ui_page.jsp' with the path to your UI page
} else {
gs.addErrorMessage('Hardware record not found.');
}
})(current, previous);
UI Page Template
<?xml version="1.0" encoding="utf-8"?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<html>
<head>
<title>Sample Table UI Page</title>
<!-- Add your CSS styles here -->
</head>
<body style="zoom: 70%">
<!-- Add your HTML content here -->
<table>
<thead>
<tr>
<th width="20">No</th>
<th>Type</th>
<th>Model</th>
<th>Serial Number</th>
<th>No inventory</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>${sysparm_sno}</td> <!-- Display serial number fetched from the UI action script -->
<!-- Add other columns as needed -->
</tr>
</tbody>
</table>
<!-- Add more HTML content here -->
</body>
</html>
</j:jelly>
Replace 'alm_hardware' with the correct table name and 'serial_number' with the field name containing the serial number in your ServiceNow instance. Also, replace 'your_ui_page.jsp' with the path to your actual UI page file.
This code will populate the serial number value from the alm_hardware record into the UI page when the UI action is triggered, and the page is loaded.
Mark as accepted solution & hit helpful !!!