
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 08:55 AM
Hello - Looking to calculate a Contract Days Left field in the contract application form.
What I have works for the most part, but I would like the output to show 0 or "Expired".
Instead it shows hours and minutes that simply do not apply.
Also, Any to only show days and NOT show hours and minutes?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2022 01:31 PM
Then, by changing the business rule I proposed to instead run on "display" and change the condition to only run if the end date is not empty should do the trick.
Another small note, I sure hope that there isn't any requirements in regards to reporting on this field. For example how many contracts do we have that has an expiry days less than 30 days.
That would still lead to the same issue as explained before, the values are not saved on the record, the value is only calculated when the record is displayed. If reporting is needed then reporting by using data on the "End date" field would be required.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 04:22 PM
Hi,
I hope my initial reply was at least helpful.
Ideally, you'd attempt this on your end and we'd have a dialog to help you learn instead of just having code be given to you. Since that has already happened by someone else replying in my reply chain here, then feel free to work with that 🙂
A business rule would be ideal to do this so that it doesn't involve the client however, depending on if that result determines actions the client needs to do in that moment, then you can use an onChange client script, for example, and GlideAjax.
We don't know the full use case here, so that's for you to decide.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 11:16 PM
Sorry for jumping ahead
Chris, just like Allen mentioned, there are a couple of options to choose from, depending on your requirement.
My solution will set the value when the save happens, so in that case the end user will not see the resulting days left until after the Save/update button is pressed. And perhaps you need to display the result directly whenever the value changes, then you would go for a different approach with GlideAjax/Script include.
Also, in my example the value calculated/stored is not dynamic, so if you set an end date that is 7 days ahead, and then look at the same record 2 days later, it will still say that it's 7 days until expiration, which might be a bit misleading.
So another option would be to calculate the value whenever the record is loaded/displayed to the user.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2022 04:54 AM
Thanks for the help.
My requirement is more when the form is loaded to calculate the days left in the contract. I also will mimic this behavior for another field. It sounds like a GlideAjax/Script would be needed, but have no idea where to start there.
A dynamic value calculated would be ideal as when form is loaded it calculates the "Contract End Date" minus "current date" = "Days Left"
I also appreciate insight to figure this out on my own, but I'm very inexperienced to code, and just want to get this particular requirement satisfied for the business.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2022 01:31 PM
Then, by changing the business rule I proposed to instead run on "display" and change the condition to only run if the end date is not empty should do the trick.
Another small note, I sure hope that there isn't any requirements in regards to reporting on this field. For example how many contracts do we have that has an expiry days less than 30 days.
That would still lead to the same issue as explained before, the values are not saved on the record, the value is only calculated when the record is displayed. If reporting is needed then reporting by using data on the "End date" field would be required.