Display a table rows as form fields in UI page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2025 03:57 PM
Can anyone tried creating a UI page or UI Macro on which to display a table rows as form fields?
Scenario: I have table with 10 records (Name, Data Type) and I want to display those 10 records as 10 fields on a form (may be UI page or Macro or I don't know which is best fit).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2025 08:52 PM
Hi dasarin
Here's how you could approach it with a UI Macro:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate>
var tableData = new GlideRecord('your_table_name');
tableData.query();
var records = [];
while(tableData.next()) {
records.push({
name: tableData.getValue('name'),
dataType: tableData.getValue('data_type'),
sysId: tableData.getUniqueValue()
});
}
</g:evaluate>
<div class="container">
<j:forEach items="${records}" var="record">
<div class="form-group">
<label for="${record.sysId}">${record.name}</label>
<j:choose>
<j:when test="${record.dataType == 'string'}">
<input type="text" class="form-control" id="${record.sysId}" name="${record.sysId}" />
</j:when>
<j:when test="${record.dataType == 'boolean'}">
<input type="checkbox" id="${record.sysId}" name="${record.sysId}" />
</j:when>
<!-- Add more data types as needed -->
</j:choose>
</div>
</j:forEach>
</div>
</j:jelly>
You can then include this macro in a UI Page:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:ui_macro name="your_macro_name" />
</j:jelly>
For more details on UI Macros, check out: UI macros
If this helps, please give it a helpful vote. And if it’s what you were looking for, go ahead and accept the solution. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2025 09:37 AM
Thank you Daniel. Will try this and let you know if this works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2025 09:02 PM
Hi @dasarin
list views in ServiceNow with enabled inline cell editing already provide exactly what you are looking for. So why do you want to reinvent the wheel and create technical debts by replicating the functionality?
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2025 09:22 AM
I would like to make field addition dynamic. So whenever needed I can add a field as a row in a table and it will be displayed as a field on form.