- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2018 05:00 AM
How can I fetch current date on a After Query/Update business Rule?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2018 06:52 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2018 05:05 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2018 06:49 AM
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;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2018 06:52 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2023 12:21 PM
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.