- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 06:20 AM
Hi All,
I would like to set a Business Rule in order to automatically assign a status for the record between Active (= 1) or Inactive (=2). The goal should be assign Active status to records that have been updated in the last 90 days, and Inactive status to records that have not been updated in the last 90 days.
So, within the table, I created a new field "Status" (u_status) where the information should be inserted, of which type is "Choice" with 2 choices: Active / Inactive; and I set up the following script in the business rule:
(function executeRule(current, previous /* null when async */ ) {
Thanks.
Vito
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 06:48 AM
Could you pls try with below updated code:
(function executeRule(current, previous /* null when async */) {
var updated = current.sys_updated_on;
var todayTs = gs.nowDateTime(); // Get current date and time
var today = todayTs.split(' ')[0]; // Extract only the date part
// Calculate the difference in days between today and the last update date
var daysSinceUpdate = gs.dateDiff(today, updated.getDisplayValue(), true);
// Set status based on the difference in days
if (daysSinceUpdate <= 90) {
current.u_status = '1'; // Active
} else {
current.u_status = '2'; // Inactive
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 06:48 AM
Could you pls try with below updated code:
(function executeRule(current, previous /* null when async */) {
var updated = current.sys_updated_on;
var todayTs = gs.nowDateTime(); // Get current date and time
var today = todayTs.split(' ')[0]; // Extract only the date part
// Calculate the difference in days between today and the last update date
var daysSinceUpdate = gs.dateDiff(today, updated.getDisplayValue(), true);
// Set status based on the difference in days
if (daysSinceUpdate <= 90) {
current.u_status = '1'; // Active
} else {
current.u_status = '2'; // Inactive
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 07:45 AM
Hello Maddysunil,
Many thanks for your reply. I used the script and it worked. The only change I made was that I reversed today and updated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 06:52 AM
How is this business rule triggered?
Why not run a scheduled flow daily (or hourly) to just do that check? Check if updated is 90 days or longer ago and update the field. Since it's 90 days, I don't think it will come to a day or an hour?
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2024 07:43 AM
Hello Mark.
This business rule is triggered only when records are inserted or updated.
Our goal is to upload data via Import Set every 90 days. So, if the record is created or updated within 90 days, we will consider it as Active; if the record isn't updated within 90 days, we will consider it as Unactive.
Anyway, thank you for the reply. I'm open to hearing alternative ideas