Servicenow atf 101: addseconds servicenow​?

Channel:
Subscribers:
1,720
Published on ● Video Link: https://www.youtube.com/watch?v=jTKlvjly71c



Duration: 0:00
1 views
0


This file helps get started w/ Servicenow atf.

i. In ServiceNow, you can use the `addSeconds()` function to add a specified number of seconds to a date or time field. Here's how you can use it:

```javascript
// Assuming you have a date/time field named 'my_date_field' in a record
// and you want to add 300 seconds (5 minutes) to it.

var gr = new GlideRecord('table_name'); // Replace 'table_name' with the name of your table
gr.get('sys_id'); // Replace 'sys_id' with the sys_id of the record you want to update

var originalDateTime = gr.getValue('my_date_field'); // Get the original date/time value
var updatedDateTime = gs.dateGenerate(originalDateTime); // Convert the original value to a GlideDateTime object
updatedDateTime.addSeconds(300); // Add 300 seconds (5 minutes)

gr.setValue('my_date_field', updatedDateTime); // Set the updated date/time value
gr.update(); // Update the record

gs.info('Updated date/time: ' + gr.getValue('my_date_field')); // Log the updated date/time value
```

In this example:

- Replace `'table_name'` with the name of the table where your record is located.
- Replace `'sys_id'` with the sys_id of the record you want to update.
- Replace `'my_date_field'` with the name of your date/time field.
- `300` represents the number of seconds you want to add. Adjust it according to your requirement.

This script will fetch the existing value of the date/time field, add 300 seconds to it, and then update the record with the new value. Make sure to test the script in a non-production environment before using it in a production instance.