- 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 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 09:35 AM - edited ‎08-08-2023 09:36 AM
Thank you for the solution. Another point is "opened date" is the day when users submit the request. So, not sure how to include opened day inside the code?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2023 09:47 PM
Hello @Sifa Tok ,
You can use current date so when user is submitting form it will pick that date as below
var today_date = new Date(); // use date or date time as per your format
var today_date_str = formatDate(today_date, g_user_date_format);
var open_Date = today_date_str;
Kindly mark correct and helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2023 06:00 AM
I am not sure which part is wrong actually. I've just tried but it shows an error as below. I need to set "openedDate" as form's submitted day for example if the users submit the request and if they select for example "5" for "How long should the server be offline before being decommissioned?" question, "Server Offline until" variable should populated automatically "5 + today's date". Can you please explain a a bit clear?
Thanks!