Business Rule to calculate the days pending
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 11:08 AM
Hello,
I have created a business rule that is supposed to fill a table column on my called Days Pending. Then I created a Business rule with the script below that needs to calculate todays date minus the lastUpdate. I need it to return just the number of days to my new column days_pending. Can someone take a look at the script below and let me know what I am missing to have it prefill the number of days to my table column please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2024 05:54 AM
Hi Kilo,
Sorry, that I didn't also reply to you, but yes, I tried that too and still the field didn't fill. As I continued researching this, I recognized we have a metric definition that contains the duration from status (state) to state. So, I started trying to figure out how I could possible pull the information over from the metric_instance an maybe fill the field days_pending using that. Below is a very rough draft of the previous code and some code that has the metric_instance and the start of some queries. Would you mind taking a look and seeing if you can put this together? I will be working on this more today, but any help would be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2024 07:08 AM
Here is another draft that is hopefully closer to what is needed:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 09:55 AM
Thanks, let me see if this helps with what I did yesterday, I appreciate it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 10:26 PM
Hi @Annette Kitzmil,
Please try this below code
(function executeRule(current, previous /*null when async*/) {
var todaysDate = new GlideDate();
var lastUpdate = new GlideDateTime(current.sys_updated_on); // This is using the "Updated" field
// Calculate the difference in days between todaysDate and lastUpdate
var daysPendingCalculation = GlideDateTime.subtract(todaysDate, lastUpdate).getNumericValue();
current.days_pending = daysPendingCalculation; // Assign the calculated value to the days_pending field
})(current, previous);
Please accept my solution if it resolves your issue and thumps 👍 up
Thanks
Jitendra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2024 10:16 AM
Hi Jitendra,
So, here is the field that I am trying to get the business rule script to fill to. The type was integer even though it is showing duration now, but just so you know what the business rule field I am looking to fill with this calculation.
Then here is the business rule I created details and the script at the bottom is where I am at now, but I also tried applying the script above and still, the column isn't showing the days.
Script to try and force a fil and it doesn't fill the field either, but you can see what is commented out. Any other suggestions on what else might be preventing it from filling the days to the field?