Data Table widget to have an option to show child records and attach attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 11:20 PM - edited 01-16-2024 11:20 PM
Hi All,
I need to customize data table widget such that I can see child records for each record show in the list, as well as give option to attach directly from the data table list view. Please help to achieve this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 11:24 PM
To customize the data table widget to show child records for each record and provide an option to attach directly from the data table list view, you can follow these steps:
1. **Clone the OOB Data Table Widget**:
- Navigate to Service Portal > Widgets.
- Search for the Data Table widget and clone it.
- Give it a unique name and ID.
2. **Modify the Server Script**:
- In the cloned widget, modify the server script to include child records.
- Use GlideRecord to query the parent table and then use GlideRecord again within that query to get the child records.
- Example:
var gr = new GlideRecord('parent_table');
gr.query();
while(gr.next()){
var childGR = new GlideRecord('child_table');
childGR.addQuery('parent', gr.sys_id);
childGR.query();
while(childGR.next()){
// add child record to data object
}
}
- This will add the child records to the data object that is returned to the client script.
3. **Modify the Client Script**:
- In the client script, modify the data object to include the child records.
- This will allow the child records to be displayed in the table.
4. **Add Attachment Functionality**:
- To add the ability to attach directly from the data table list view, you will need to add a button or link in the HTML template that calls a function in the client script.
- This function should use the NOW.attachments service to open the attachment dialog.
- Example:
$scope.attach = function(record){
NOW.attachments.dialog(record.sys_id, 'table_name');
}
- This will open the attachment dialog for the selected record.
5. **Modify the HTML Template**:
- In the HTML template, add a new column for the attachments.
- In this column, add a button or link that calls the attach function when clicked.
- This will add a button to each row in the table that opens the attachment dialog when clicked.
6. **Test the Widget**:
- Finally, add the widget to a page in the service portal and test it to make sure it works as expected.
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - nowgpt.ai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 02:19 AM
Could you please provide some screen shot of same to understand better.
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]
****************************************************************************************************************