Need to set the default value of days filed
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 06:35 AM
Hi team,
We have one field "Expire Days" need to set the default value based on the difference between the current date and the end date.
For example:
Current Date is: 2023-08-18
End date: 2023-08-30
We need to set the value Expire Days as 12 days
Regards,
Mahesh
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 06:46 AM
Hi @maheshch18,
You need to write before insert/update business rule to calculate the difference between current date and end date.
Sample scripts:
var today = new GlideDateTime(); // gives current date-time
var end_date_time = new GlideDateTime('current.u_end_date'); // add end date field/column
var diff = GlideDateTime.subtract(today, end_date_time);
var days = diff.getRoundedDayPart();
current.expiry_days_field = days;
If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar
The world works with ServiceNow