Script to Calculate Expiration date on catalog item variable( cat_item is scoped app)

geet
Tera Guru

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.

geet_0-1695667964100.png

Please help how this can be achieved.

1 REPLY 1

Alex Tod1
Kilo Sage

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