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

Hi @Ankur Bawiskar  I have already tried just by removing current.update(). But it was not working. If I use current.update() its working

Hi,

your BR should have Before type and Insert - True

Share your BR configuration screenshot

regards
Ankur

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

Aman Kumar S
Kilo Patron

For before BR, update() is not needed, if at all you have any issues with this.

Try setting default value for the field at dictionary level, Configure dictionary, Default Value section:

javascript: gs.nowDateTime();

Best Regards
Aman Kumar