How to create form view using script or on action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hello team,
I have a requirement where user will select a table name and click on submit button.
post submit, it should create a form view for that table with all of the fields in the table.
Is this feasible using script or any OOTB ui action without manual intervention.
Thank you
Sunil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @sunilsargam It's not best practice. The view should be created by the Admin or a role with specific permissions. and ServiceNow provides a standard way to do that. Let's follow that.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
Hi @sunilsargam ,
Out of the box, ServiceNow doesn’t provide a way to dynamically generate a form view for an arbitrary table at runtime just by selecting the table name. Form layouts are normally designed manually in Form Designer or Form Layout for each table.
Scripting approach (possible)
If you want to generate a dynamic form:
You could build a custom UI Page or a Service Portal Widget / Workspace Component.
The script would take the table name, query the sys_dictionary table to retrieve all active fields for that table, and then render them dynamically in a form-like structure.
- An example script to fetch all active records of a table:
var tableName = 'incident'; // dynamically chosen
var dictGR = new GlideRecord('sys_dictionary');
dictGR.addQuery('name', tableName);
dictGR.addQuery('internal_type', '!=', 'collection'); // skip references
dictGR.query();
while (dictGR.next()) {
gs.info('Field: ' + dictGR.element + ' | Label: ' + dictGR.column_label);
}
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I recommend not doing this as that's not how form views are created.
Please inform your customer about this.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader