Populate Date Field Based on Another Field on Catalog form

Sifa Tok
Tera Contributor

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?" fieldMicrosoftTeams-image (45).png

1 ACCEPTED SOLUTION

Samaksh Wani
Giga Sage

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

View solution in original post

7 REPLIES 7

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

Chetan Mahajan
Kilo Sage

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

-O-
Kilo Patron

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?