- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2023 02:19 PM
Hello experts, please I need your help, when users create a knopwledge article, there is a "valid to" field that automatically sets it for a year, I created an onChange client script that does not let the users add more than 365 days and it is workng fine, but I was asked to create an onSubmit script instead or a BR, so I went ahead and tried to create an onSUbmit client script but it is not working, here is the code:
but at the time I click "submit" adding more than a year, it gives me a javascript error,
what am I doing wrong? can you help me out?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2023 08:08 PM - edited 05-12-2023 08:10 PM
@Jesus Nava Your client script is returning an error because on line number 3 you have used a variable newValue which isn't defined anywhere inside the script. You probably copied this code from an onChange script where newValue parameter is available in function argument. However, newValue isn't available inside an onSubmit script.
Try fetching the value data from an existing field on the form as follows.
g_form.getValue('field_name');//replace field name with the name of your field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2023 01:10 AM
Hi @Jesus Nava
Please use something like this in your first two line of codes
var gdt = new Date(g_form.getValue('name_of_your_field'));
var current_date = new Date();
If this resolved your issue, then please don't forget to mark as correct or helpful.
Regards
Devender

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2023 08:08 PM - edited 05-12-2023 08:10 PM
@Jesus Nava Your client script is returning an error because on line number 3 you have used a variable newValue which isn't defined anywhere inside the script. You probably copied this code from an onChange script where newValue parameter is available in function argument. However, newValue isn't available inside an onSubmit script.
Try fetching the value data from an existing field on the form as follows.
g_form.getValue('field_name');//replace field name with the name of your field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 09:20 AM
Thank you it worked perfectly!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2023 01:10 AM
Hi @Jesus Nava
Please use something like this in your first two line of codes
var gdt = new Date(g_form.getValue('name_of_your_field'));
var current_date = new Date();
If this resolved your issue, then please don't forget to mark as correct or helpful.
Regards
Devender
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 09:21 AM
Thank you it worked perfectly!!