Script to Calculate Expiration date on catalog item variable( cat_item is scoped app)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 12:03 PM
Hi,
I have 3 variables on the catalog item as follows.
I want to calculate the "calculated expiration Date" based on the "start time" of the access and the "duration" selected on the variable.
Example: start time is - 2023-09-26 11:50:40 and duration is Days=1 and Hours 2 that means for total 26 hours the person needs access and his access should be revoked on 2023-09-27 13:50:40.
Start Time and Duration are both selected by user for raising access request.
Duration will have a default value based on the type of request user is raising but user can change the duration.
Please help how this can be achieved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 12:50 PM
Hi @geet,
You have to create a client script (onChange) and a script include because you need the "GlideDateTime" function which is on the server side. You can use the example from here as a reference: https://www.servicenow.com/community/developer-forum/how-to-add-hours-to-a-date-time-value/m-p/15266...
In the script include part you will have:
var hours = 60 * 60 * duration;
Mark Correct or Helpful if it helps.
Thanks,
Alex