How to auto populate date based on choice field

charan_1
Tera Contributor

Scenario is to populate date out based on a choice field and the date out has to get incremented based on choice i select in choice field and the date in value is current date. How to populate date out when i select any choice on a choice field

7 REPLIES 7

  var currentDateTime = new GlideDateTime();
        currentDateTime.addDaysLocalTime(dateAdd);
use this on line 16,17,18

Pushkar-Snow
Mega Guru

Hi @charan_1 ,

 

Based on your description I Assume you are trying to increment the Current Date with the selected choice value it might be Date in the numbers.

 

I can suggest you below steps to perform:

1] Write onChange client script for the choice field you are changing/selecting to increment the number of days to current date

2] Create script include and call from onChange script above to perform server side action

3] In script include you can pass the selected choice value as a parameter and return calculated date

4] You can used GlideDate API to add the selected number of days to current date. Below code might be helpful:

5] You can set the calculated value returned from script include to the current date field

g_form.setValue('curr_date_field',<value returned from Script include>);

 

Provided below URLs for GlideDate and Script Include for you reference

https://docs.servicenow.com/en-US/bundle/tokyo-application-development/page/script/ajax/topic/p_AJAX...

https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/c_APIRef

 

If I am able to help you with your question, Please click the Thumb Icon and mark as Correct. 

 

Regards,

Pushkar

Ankur Bawiskar
Tera Patron
Tera Patron

@charan_1 

you can achieve this with only client script OR with client script + GlideAjax

can you share what script did you try so far and what didn't work?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader