Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Radio Buttons Creating Time Stamps?

jonathannel
Kilo Contributor

Good Morning All,

 

I've searched but can't find anyone asking about a way to use radio buttons to create a visible time/date stamp. Right now, I am using a form log where radio buttons are used for showing start and completion of a task. Currently the creation of the task log "created" is being used for a start time and "modified" is being used for an end time, however in situations where a task is complete but the record needs adjustment after the fact, the "modified" time does not work.

 

Is there a way to have when the radio button is selected a time/date stamp is recorded visibly?

 

Thanks

1 REPLY 1

Community Alums
Not applicable

 

Yes! You can achieve this in ServiceNow by using Client Scripts to capture timestamps when a radio button is selected and store them in visible fields.


Solution Approach

  1. Add two new date/time fields (start_time and completion_time) to the form.
  2. Use an onChange Client Script to capture the timestamp when the user selects a radio button.

Final Client Script

 

js
CopyEdit
(function executeRule(current, gForm, gSNC) { var selectedValue = gForm.getValue('radio_button_field'); // Replace with actual field name var currentTime = new Date().toISOString(); // Get current timestamp in UTC format if (selectedValue === 'start') { gForm.setValue('start_time', currentTime); // Set Start Time } else if (selectedValue === 'completed') { gForm.setValue('completion_time', currentTime); // Set Completion Time } })(current, gForm, gSNC);
 

🔹 Steps to Implement:

  1. Navigate to your ServiceNow instance.
  2. Go to "Client Scripts" (System Definition > Client Scripts).
  3. Create a new Client Script with:
    • Type: onChange
    • Table: Your target table (e.g., task_log)
    • Field: Your radio button field (radio_button_field)
    • Script: Copy & paste the above script.
  4. Save & Test 🚀

🔹 How It Works:

✔ When "Start" is selected, the Start Time field is updated.
✔ When "Completed" is selected, the Completion Time field is updated.
✔ The timestamp remains unchanged even if modifications occur later.

This way, you get a reliable time log for task completion without relying on "modified" timestamps.