- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 04:54 AM
Hi All,
There are two filed on the catalog form. One is date and another one is Project that have drop down value example ab and cd. I want to populate date field based on the Project drop down value.
If ab is selected in Project then date should be auto populate one year from now and if cd value is selected then date should be auto populate two years from now.
Right now I have below code.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var getChoiceValue = g_form.getValue('test'); // variablename
if (getChoiceValue == 'ab') {
var todayDate = new Date(new Date().setFullYear(new Date().getFullYear() + 1)); // Now
g_form.setValue('date', todayDate.toISOString().slice(0, 10));
} else if (getChoiceValue == 'cd') {
var todayDate1 = new Date(new Date().setFullYear(new Date().getFullYear() + 2)); // Now
g_form.setValue('date', todayDate1.toISOString().slice(0, 10));
}
}
For example today is 21/07/2022 and if I select ab then it is showing 21/07/2023 but it should be 20/07/2023. Also for two year it should be 20/07/2024.
Please suggest on this.
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 05:05 AM
Refer below thread and checkout addDateTimeAmount part and use 365 days
https://community.servicenow.com/community?id=community_question&sys_id=38c40be9dbd8dbc01dcaf3231f9619e3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 05:05 AM
Refer below thread and checkout addDateTimeAmount part and use 365 days
https://community.servicenow.com/community?id=community_question&sys_id=38c40be9dbd8dbc01dcaf3231f9619e3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 05:08 AM
Hi Brijmohan,
Please change your code with following code to add 1 year from now
new GlideDateTime(gs.nowDateTime());
gdt.addYears(1);
g_form.setValue('date', gdt.getDate());
Please Mark ✅ Correct/helpful, if applicable.
Thanks,
Srinivasulu Laggala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 06:55 AM
Thanks for you response but as I know we can not use "gs" in client script. can we??