How to auto populate date based on choice field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2023 12:09 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2023 12:17 AM
[client script - onChange] for the choice list..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2023 12:19 AM
Hi @charan_1 ,
I didn't quite understand that incremental part. Can you explain with an example?.
Regards,
Johns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2023 12:39 AM
Example :date in is current date and assume the choice field has 3 choices it is a,b,c if i select the choice a then date out has to be date in+1, if i select the choice b then it has to be date in+2 if i select c then it has to be date in+3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2023 01:11 AM - edited ‎02-09-2023 01:12 AM
Hi @charan_1 ,
for this requirement, you need to create a script include and onChange client script.
I had created using the sample data. you can try that with your correct data.
Script Include:
getDateOutField: function() {
var choiceData = this.getParameter('sysparm_choiceData');
var dateAdd = 0;
if (choiceData == 'a') { //replace the choice with correct values from choice (not label use value of choice)
dateAdd = 1;
} else if (choiceData == 'b') {
dateAdd = 2;
} else if (choiceData == 'c') {
dateAdd = 3;
}
var currentDateTime = new GlideDateTime(gs.now());
currentDateTime.addDays(dateAdd);
var currentDate = currentDateTime.getDate();
return currentDate;
},
Client Script:
var choiceData = g_form.getValue('u_choice_date');
var ga = new GlideAjax('PopulateDateOutField'); //script Include name
ga.addParam('sysparm_name', 'getDateOutField'); //script include function
ga.addParam('sysparm_choiceData',choiceData);
ga.getXMLAnswer(getDate);
function getDate(answer){
g_form.setValue('u_date_out',answer); //set the values using the correct fields
}
I will attach the results in the attachment. hope you were looking for this solution.
Mark helpful and accept the solution if it helps in solving your query.
Regards,
Johns