Create a record to a table when user put the inputs in a pop up window form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 11:55 PM
Hi Community,
I have a ui action on incident form. When user clicks on this ui action, it will display a pop up window with some fields to be filled in and to create a record in a table.
Pasting my code below:
UI Action:
Table: Incident
Action name: Register Time Worked
Show insert, show update, client and form button checked.
Onclick: registercall()
Script:
When user clicks on cancel button, its cancelling this window. When user clicks on ok button its doing nothing, even its not submitting the details which user has entered on this form.
I want to create a record in a table when user clicks on ok button and map these fields to those fields which are there in that table.
Thanks,
Poorva Bhawsar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 08:10 PM
HI @Poorva Bhawsar ,
I trust you are doing great.
It seems like your UI Action and UI Page setup in ServiceNow are functioning correctly, but there's an issue with the update_ticket
client script that is supposed to create a record in the task_time_worked
table. The problem likely lies in the way you are trying to capture and send the form data to the server.
Your current update_ticket
function needs to be modified to correctly capture form data. Here’s a revised version:
function update_ticket() {
var user = document.getElementById('user').value;
var action = document.getElementById('action').value;
var call_responded = document.getElementById('callrespon').checked;
var call_not_responded = document.getElementById('callnotrespon').checked;
var days = document.getElementById('days').value;
var hours = document.getElementById('hours').value;
var minutes = document.getElementById('minutes').value;
var seconds = document.getElementById('seconds').value;
var comments = document.getElementById('comments').value;
var time_worked = calculateTimeWorked(days, hours, minutes, seconds);
var gr = new GlideRecord('task_time_worked');
gr.initialize();
gr.setValue('user', user);
gr.setValue('action', action);
gr.setValue('u_call_responded', call_responded);
gr.setValue('u_call_not_responded', call_not_responded);
gr.setValue('time_worked', time_worked);
gr.setValue('comments', comments);
gr.insert();
}
You need a function to calculate the time worked based on days, hours, minutes, and seconds. Here's an example:
function calculateTimeWorked(days, hours, minutes, seconds) {
// Convert everything to seconds and sum up
var totalSeconds = parseInt(days) * 86400 + parseInt(hours) * 3600 + parseInt(minutes) * 60 + parseInt(seconds);
return totalSeconds; // You can format this as needed
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi