Get current date on a Business Rule

anirban300
Kilo Guru

How can I fetch current date on a After Query/Update business Rule?

1 ACCEPTED SOLUTION

can you help me out with the full code here.

 

if you are writing the BR on the kb_knowledge table,then use

var gDate = new GlideDate();

 current.valid_to =gDate;

current.update(); //based on your when to run condition use this one.

 

If the business rule is before insert or update BR, then system automatically does an update on the database when the script runs, and it doesnt need another current.update() in the script.

 

 

 

 

 

View solution in original post

5 REPLIES 5

ScienceSoft
Tera Guru
gs.nowDateTime()

or
var gDate = new GlideDate();

 

As ServiceNow provides such functionality - you may also find this article useful: 

https://docs.servicenow.com/bundle/jakarta-application-development/page/script/server-api/concept/c_GlideDateTime.html

 

 

anirban300
Kilo Guru

Should I write the script in the business rule like below?

 

var gr = new GlideRecord('kb_knowledge');

var gDate = new GlideDate();

gr.valid_to = gDate;

can you help me out with the full code here.

 

if you are writing the BR on the kb_knowledge table,then use

var gDate = new GlideDate();

 current.valid_to =gDate;

current.update(); //based on your when to run condition use this one.

 

If the business rule is before insert or update BR, then system automatically does an update on the database when the script runs, and it doesnt need another current.update() in the script.

 

 

 

 

 

Community Alums
Not applicable

current.update() should not be used in Business Rules.  This can, and will often lead to infinite loops.  Additionally, current.update() in any Business Rule will flag in any Instance Scan.