Business Rule to update the field with current date and time

Sumedh Gajbhiye
Tera Contributor

Hello Guys,

When ever a record gets inserted on incident table a datetime field is populated with current date and time.

I have a field on the incident form which has type date/time.

For that I have created the Before Business rule of insert type. Below is my code:-

// Add your code here
var dateTime = new GlideDateTime();
current.setValue('u_request_received_date',dateTime);
current.update();

Now I don't want to use current.update() method. And if I remove this, it does not work. 

Please help me with this one 😞 

Note: I need to use only Business Rule.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

If you use before insert business rule which you are already using then no need of current.update();

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Sagar Pagar
Tera Patron

Hi,

Try this in your before business rule with-out current.update();

 

current.u_request_received_date = gs.nowDateTime();

 

Thanks,

Sagar Pagar

The world works with ServiceNow

@Sagar Pagar Tried this one... but doesn't work.

Hi,

Have you verified by creating a new Record and submit/save it. The script is fine. It should work.

 

Note - No need to use of current.update(); in before business rule. Its not a best practice, it will goes into recursion.

 

Thanks,
Sagar Pagar

The world works with ServiceNow

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

If you use before insert business rule which you are already using then no need of current.update();

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader