- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2023 03:48 AM
Hi, I'm new to ServiceNow and Java . I'm struggling to create a simple logic how I can set the date field based on another field. I need to set "Server Offline until" field should be populated using the formula Opened date + number of days selected "How long should the server be offline before being decommissioned?" field
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2023 04:24 AM
Hello @Sifa Tok
You can write a Catalog Client Script :-
var openedDate = g_form.getValue('opened_date');
var days = g_form.getValue('how_long_server...');
openedDate.addDays(days);
g_form.setValue('server_offline_until',openedDate);
Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2023 10:20 PM
Hello @Sifa Tok
You can use onSubmit Client Script for that :-
getDay(); it is a javascript function it will return the day number after that you can use if else ladder, for appending the name of day like :-
if(day==3){
// wednesday
}
and you can add the day in the field with concatenation.
Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.
Regards,
Samaksh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2023 04:56 AM
Hello @Sifa Tok ,
You can write onChange client script on change how long should.... as below
// assuming you have glide date fields
var openDate = new Date( g_form.getValue('opened_date'));// change field name accordingly
var offlineDuration = parseInt(g_form.getValue('how_long_offline')); // change field name
var getopendate = openDate.getDate();
var totalDays = parseInt(getopendate)+ parseInt(offlineDuration);
openDate.setDate(getopendate);
g_form.setValue('Server_offline',openDate); // change field name
Kindly mark correct and helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2023 03:36 PM
Do you still need help with this?
If yes:
- Is there a field that holds "Opened date" or should that be just today?
- Does it matter if the offline till date falls on a weekend or public holiday?