Set DateTime field From Another DateTime Field and Add 15 Minutes

DeJohnson
Tera Contributor

Hello, 

 

I'm trying to set a specific DateTime field using the sys_created_on field on a form. I have tried using a business rule but I cannot seem to get it to work. 

 

How can I set a field to the sys_created_on field + 15 minutes after insert?

 

Open to any suggestions!


Thank you,

 

Derek

1 REPLY 1

Riya Verma
Kilo Sage
Kilo Sage

HI There,

  1. Click on "New" to create a new Business Rule.
  2. Provide a meaningful name and a short description for the Business Rule.
  3. Set the "When to run" condition to "After" and choose "Insert" as the operation.
  4. In the "Advanced" section of the Business Rule form, write the following code in the "Script" field:
(function executeRule(current, previous) {
  var timeToAdd = 15 * 60 * 1000; // 15 minutes in milliseconds
  var createdOn = new GlideDateTime(current.sys_created_on);
  var newDateTime = createdOn.getNumericValue() + timeToAdd;
  current.target_datetime_field = new GlideDateTime(newDateTime);
})(current, previous);
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma